Search code examples
androidlayoutsizefixedfill

How to fill the screen with only one element?


I want to make an activity with 2 elements in the screen, one in the bottom, with a fixed size, and one on top of this which one must fill the screen.

Desired layout

How I can do that in a Layout?

Thank you


Solution

  • Use below code:

    <LinearLayout 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"
        android:orientation="vertical"
        tools:context=".MainActivity" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/hello_world" />
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:text="test" />
    
    
    
    </LinearLayout>