Search code examples
androidandroid-linearlayout

Android gravity in linearlayout with weightSum won't go at bottom


I have this scenario:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".Functions">

    <ScrollView>
    [ some elements inside]
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="2"
        android:orientation="vertical"
        android:gravity="bottom">

        <Button
            android:id="@+id/btnSave"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textSize="18dp"
            android:height="60dp"
            android:tint="@color/area_bck"
            android:backgroundTint="@color/area_frg"
            android:text="@string/save_btn"
            android:layout_weight="1"
            android:layout_margin="5dp" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2">

            <TextView
                android:id="@+id/lbltvAppVersion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="4dp"
                android:visibility="visible"
                android:layout_gravity="left"
                android:textSize="17dp"
                android:textStyle="bold"
                android:text="@string/application_version" />

            <TextView
                android:id="@+id/tvAppVersion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="4dp"
                android:visibility="visible"
                android:layout_toRightOf="@+id/lbltvAppVersion"
                android:textColor="@color/area_frg"
                android:textStyle="bold"
                android:textSize="17dp" />

        </RelativeLayout>

    </LinearLayout>

</FrameLayout>

where I would put the LinearLayout with weightSum at bottom of the screen but it won't even if I read somewhere to use android:gravity="bottom" in LinearLayout... I tried also using layout-gravity too and also putting android:gravity in each of elements in the button and the relativelayout elements inside that LinearLayout but without success... shall I did something wrong or forgot something more to consider?... Any direction would be appreciated... Thanks in advance!

Cheers!


Solution

  • Your LinearLayout has a android:layout_height="match_parent" so it matches all of FrameLayout's height. if you want it to go to bottom of screen, just make that android:layout_height="wrap_content"