Search code examples
androidscrollview

android: ScrollView parent can't resolve the weight


I have a weird issue. As you can see in my code below, for hor_LnI have set the android:layout_weight to 50, therefore it should fits 50% of height of the screen to fill button's height also, however it does not.

Although if I change the ScrollView to LinearLayout as parent layout, it seems original and correct.

Here is my code:

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


    <LinearLayout
        android:id="@+id/vertical_Ln"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:weightSum="100"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/hor_Ln"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:weightSum="10"
            android:layout_weight="50">

            <Button
                android:layout_width="0dp"
                android:layout_weight="5"
                android:layout_height="match_parent" />


        </LinearLayout>

    </LinearLayout>

</ScrollView>

Here is the output:

Picture

What is the problem?


Solution

  • You have to include property android:fillViewport="true" to make your ScrollView full screen.