2

my Android TextView xml is very simple like below, I used style ScrollView but it won't show scrollbar, even when the text is exceeding the bottom and there is no way for me to see what's beyond. How to enable the scrollbar please? I think "match_parent" has issue but don't know how to fix. Thanks!

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ffffff">

        <TextView
        android:id="@+id/textResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:layout_below="@+id/buttonRecord"
        android:layout_marginTop="16dp"
        android:background="@drawable/back"
        android:editable="true"
        android:height="150dp"
        android:text=""
        android:enabled="false"

        android:scrollbars="vertical"
        style="@android:style/Widget.ScrollView"
            android:layout_alignRight="@+id/buttonRecord"
            android:layout_alignEnd="@+id/buttonRecord"
            android:layout_alignLeft="@+id/buttonRecord"
            android:layout_alignStart="@+id/buttonRecord" />

</RelativeLayout>
ykcadcg
  • 73
  • 1
  • 10

2 Answers2

0

If you want the content to scroll, perhaps try giving it a fixed height? Right now the height is set to wrap_content due to layout_height. I don't think you should be using android:height at all

Andrew Orobator
  • 7,978
  • 3
  • 36
  • 36
0

If you want a fixed height TextView to scroll vertically with scrollbar, define your XML layout file:

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:text="@string/text_string" />

define your Java class file:

TextView tv = (TextView) findViewById(R.id.textView);
tv.setMovementMethod(new ScrollingMovementMethod());
Akanksha Hegde
  • 1,738
  • 11
  • 14
  • This approach is broken - fling won't work. The scroll will stop as soon as you lift your finger off the screen. – zyamys Apr 04 '18 at 18:34