2

I'd like to make a TextView scrollable when the maxLines is >= to 10. I tried this code:

<LinearLayout
            android:id="@+id/powers_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:orientation="vertical">

            <TextView
                android:id="@+id/powers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxLines="10"
                android:scrollbars="vertical"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:text="Powers"
                android:textSize="@dimen/primary_text_size"/>

</LinearLayout>

with this:

TextView textPowers = (TextView) findViewById(R.id.powers);
textPowers.setMovementMethod(new ScrollingMovementMethod());

I can see the scroll bar but the TextView doesn't scroll correctly. I also tried to use a ScrollView without success. The only way I found to run it is to set the ScrollView height like this:

<android.support.v4.widget.NestedScrollView
                android:id="@+id/scroll_powers"
                android:layout_width="match_parent"
                android:layout_height="180dp">

                    <TextView
                        android:id="@+id/powers"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingLeft="@dimen/activity_horizontal_margin"
                        android:paddingRight="@dimen/activity_horizontal_margin"
                        android:scrollbars="vertical"
                        android:text="Powers"
                        android:textSize="@dimen/primary_text_size"/>


</android.support.v4.widget.NestedScrollView>

but in this case I would continue to have an height of 180dp even when the lines are less than 10. What can I do? I've read many problems like this on stackoverflow like: Making TextView scrollable on Android but without success.

Ridan
  • 39
  • 4
  • Why did you use nested ScrollView? Is there a ScrollView or listview around that? – OneCricketeer Jun 11 '17 at 12:50
  • You could attempt to dynamically add the ScrollView in the Java code. You're not limited to mostly xml properties – OneCricketeer Jun 11 '17 at 12:53
  • @cricket_007 yes, I have a parent ScrollView which contains some LinearLayouts inside. I want to scroll a TextView inside one of these LinearLayouts – Ridan Jun 11 '17 at 13:18

0 Answers0