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?

GitaarLAB
  • 13,494
  • 9
  • 51
  • 74
dam
  • 53
  • 1
  • 9
  • 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. – arun Aug 19 '15 at 13:04
  • you can refer http://developer.android.com/reference/android/widget/ScrollView.html – arun Aug 19 '15 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? – dam Aug 19 '15 at 13:15
  • see this scrollview inside scrollview http://stackoverflow.com/questions/4490821/scrollview-inside-scrollview – arun Aug 19 '15 at 13:36
  • Thank you, I understand better now. – dam Aug 19 '15 at 14:00

2 Answers2

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>
IntelliJ Amiya
  • 70,230
  • 14
  • 154
  • 181
  • 1
    Thank you but not working neither...It does exactly the same thing that what I described! – dam Aug 19 '15 at 12:55
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

Community
  • 1
  • 1
dam
  • 53
  • 1
  • 9
  • 1
    Welcome to StackOverflow. I took the liberty to migrate your answer (that you edited into in your question) to... (drumroll...) your *answer*. – GitaarLAB Aug 19 '15 at 15:11