0

I have a ScrollView at the top node of an activity, with several TextView inside. I want some of these (1 out of 2) TextView scrollable themselves. They are doing more than 5 lines each but I want visitor see only 5 lines and have to scroll to watch the complete text. But what I do... doesn't work:

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="italic" android:text = "Blabla"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blanc" android:maxLines="5" android:scrollbars="vertical" android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="italic" android:text = "Blabla"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blanc" android:maxLines="5" android:scrollbars="vertical" android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="italic" android:text = "Blabla"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blanc" android:maxLines="5" android:scrollbars="vertical" android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/> </LinearLayout> </ScrollView> 

Doing that, TextViews put 5 first lines, but they are not scrollable.

What do I do wrong?

5
  • Scrollview can have only one child view it doesn't bother its child's child view. You need to add scrollview for each textview you want. Commented Aug 19, 2015 at 13:04
  • you can refer developer.android.com/reference/android/widget/ScrollView.html Commented Aug 19, 2015 at 13:06
  • Ok thanks I understand that I can't use a scrollable view inside a ScrollView. But how do I do when I need to have a scrolling view in a part of the screen the visitor doesn't see? I mean to see the scrolling view on the screen I need the screen to be scrollable...So I have to use a ScrollView and inside my scrolling view, no? Commented Aug 19, 2015 at 13:15
  • see this scrollview inside scrollview stackoverflow.com/questions/4490821/… Commented Aug 19, 2015 at 13:36
  • Thank you, I understand better now. Commented Aug 19, 2015 at 14:00

2 Answers 2

1

Try this way,

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="italic" android:text = "Blabla"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blanc" android:maxLines="5" android:scrollbars="vertical" android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="italic" android:text = "Blabla"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blanc" android:maxLines="5" android:scrollbars="vertical" android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="italic" android:text = "Blabla"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blanc" android:maxLines="5" android:scrollbars="vertical" android:text="Blablabla1\nBlablabla2\nBlablabla3\nBlablabla4\nBlablabla5\nBlablabla6\nBlablabla7\nBlablabla8\n"/> </LinearLayout> </ScrollView> 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you but not working neither...It does exactly the same thing that what I described!
1

ScrollView or no doesn't matter. The solution is to do that more in you Java Code:

textviewtv.setMovementMethod(new ScrollingMovementMethod()); 

Thanks : Android:Textview with vertical scrolling text

1 Comment

Welcome to StackOverflow. I took the liberty to migrate your answer (that you edited into in your question) to... (drumroll...) your answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.