wonggr
wonggr

Reputation: 519

LinearLayout not scrolling with ScrollView

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!

Upvotes: 5

Views: 7275

Answers (3)

Jay Rathod
Jay Rathod

Reputation: 11255

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>

Upvotes: 1

Devrath
Devrath

Reputation: 42854

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

Upvotes: 1

Ahmed S. Durrani
Ahmed S. Durrani

Reputation: 1585

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>

Upvotes: 1

Related Questions