ScrollView-如何在ScrollView中启用水平滚动

问题描述 投票:0回答:2

所以我有一个ScrollView,里面有一个TextView。当文本的String大于屏幕宽度时,它仅在下一行移动。我想通过在HorizontalScrolling中添加ScrollView来避免新的衬砌。另外,我想选择文本,以便用户可以复制文本。有可能吗?

        <ScrollView
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

                <TextView
                    android:id="@+id/text_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginEnd="15dp"
                    android:layout_marginBottom="15dp"
                    android:ellipsize="end"
                    android:textIsSelectable="true"
                    android:justificationMode="inter_word"
                    android:lineSpacingExtra="5dp"
                    android:textSize="15sp"
                    tools:targetApi="o" />
        </ScrollView>
java android textview scrollview
2个回答
0
投票
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:scrollbars="vertical">

    <HorizontalScrollView 
        android:layout_width="match_parent" android:layout_height="wrap_content">

        <FrameLayout android:layout_width="320dp"
            android:layout_height="match_parent" 
            android:background="#000000"/>

    </HorizontalScrollView>

</ScrollView>

0
投票

尝试一下:

<HorizontalScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<TextView 
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:scrollHorizontally="true"
        android:text="Horizontal scroll text view"/>

</HorizontalScrollView>
© www.soinside.com 2019 - 2024. All rights reserved.