Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 239
Prince Dholakiya Avatar asked Dec 14 '22 16:12

Prince Dholakiya


2 Answers

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>
like image 111
VIISHRUT MAVANII Avatar answered May 23 '23 20:05

VIISHRUT MAVANII


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"

like image 42
Vivek Kachhwaha Avatar answered May 23 '23 20:05

Vivek Kachhwaha