Search code examples
androidlayout

How to place frame layout in bottom in the linear layout


I am creating custom keyboard in Android. Keyboard view will be in frame layout. And I want to place this frame layout in bottom in the linear layout. Please give some idea for this.

<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Testing"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Testing 2"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Testing 3"/>

    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="bottom|end"
        android:layout_gravity="bottom">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Custom Keyboard"/>

    </FrameLayout>

</androidx.appcompat.widget.LinearLayoutCompat>

Solution

  • The easiest way is to put a View with the attribute android:layout_weight = "1" between the last TextView and the FrameLayout

    ...
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Testing 3"/>
    
    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
    
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="bottom|end"
        android:layout_gravity="bottom">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Custom Keyboard"/>
    
    </FrameLayout>
    
    ...
    

    Anyway, in this case I suggest using Relative Layout or, better, Constraint Layout