【问题标题】:ScrollView - How to enable horizontal scrolling in ScrollViewScrollView - 如何在 ScrollView 中启用水平滚动
【发布时间】:2020-04-21 05:47:24
【问题描述】:

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

        <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>

【问题讨论】:

  • ScrollView 应该是水平和垂直的。
  • 有一个叫orientation的属性设置为horizontal你会确认它是否适合你
  • @hiwajalal 谢谢,我想通了。这很有帮助。

标签: java android textview scrollview


【解决方案1】:
<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>

【讨论】:

    【解决方案2】:

    试试这个:

    <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>
    

    【讨论】:

    • ScrollView 应该是水平和垂直的。
    猜你喜欢
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 2011-07-13
    相关资源
    最近更新 更多