Prince Dholakiya
Prince Dholakiya

Reputation: 3391

How can I set LinearLayout height as match parent within ScrollView

Below is my .XML code. Could I have a solution to this problem.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/ticket_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:isScrollContainer="true">

    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</ScrollView>

Upvotes: 3

Views: 2417

Answers (3)

VIISHRUT MAVANII
VIISHRUT MAVANII

Reputation: 12648

Try This I think It may help you.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/ticket_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="true">

        <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    </ScrollView>

Upvotes: 11

Vivek Kachhwaha
Vivek Kachhwaha

Reputation: 96

Thie LinearLayout should have android:layout_height="wrap_content"

Reason for that is that if the scrollview's child is the same size as the scrollview itself (both match_parent for height) it means that there is nothing to scroll through, since they are of same size and the scrollview will only be as high as the screen.

If the LinearLayout has a height of wrap_content then the height is not related to the height of the screen and the scrollview will be able to scroll through it.

Just remember that a scrollview can only have one direct child and that child needs android:layout_height="wrap_content"

Upvotes: 4

MR.Iraji
MR.Iraji

Reputation: 54

It is meaningless to define a LinearLayout with match parent height in a ScrollView. You must set the LinearLayout height to wrap content to be able to scroll it.

Upvotes: 0

Related Questions