5

I have a LinearLayout that has a lot of TextViews programatically put in. By a lot, I mean it extends beyond the bottom of my screen. I want to use a ScrollView to allow the user to scroll beyond the screen and see the rest of the TextViews. This is my activity_main.xml currently:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >
</LinearLayout>

</ScrollView>

Any help will be greatly appreciated! Thanks!

wonggr
  • 519
  • 1
  • 5
  • 13

3 Answers3

1

Try changing android:layout_width="wrap_content" to android:layout_width="match_parent"

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >
</LinearLayout>

</ScrollView>
Ahmed S. Durrani
  • 1,535
  • 2
  • 17
  • 41
1

Change your code as below !

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >

</LinearLayout>

</ScrollView>

NOTE: To see if it is scrolling or not try placing some views inside linearLayout like buttons otherwise you won't notice the screen scrolling

Devrath
  • 42,072
  • 54
  • 195
  • 297
1

Also You Can Do Like This.It Works Well.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollData"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >



     <LinearLayout
        android:id="@+id/linearWhere"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="vertical"
        android:padding="5dp">

      </LinearLayout>
</ScrollView>
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58