0

So I have a ScrollView which has a TextView inside. When the String for the text is longer than the screen width, It simply shifting in the next line. I want to avoid the new lining by adding HorizontalScrolling in ScrollView. Also, I want to make the text selectable so the user can copy the text. Is it possible?

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

2 Answers2

0

Try this:

<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>
Dinesh
  • 1,410
  • 2
  • 16
  • 29
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>
Ravi
  • 2,277
  • 3
  • 22
  • 37