In the layout two LinearLayout left and right.

  1. How to press the right (second) LinearLayout to the right side?
  2. How to give all the remaining space to the left LinearLayout to remove the "hard size" (in 200dp )?

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <LinearLayout android:layout_height="match_parent" android:layout_width="200dp" > <ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="right" > <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Btn1" /> <Button android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Рисовать" /> <Button android:id="@+id/btn3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Установки" /> </LinearLayout> </LinearLayout> 

    1 answer 1

    For the first LinearLayout :

    1. Change the value of the android:layout_width from 200dp to 0dp ;
    2. Set the android:layout_weight="1" attribute android:layout_weight="1" .

    In this case, the second LinearLayout in width will occupy only the space it needs, and all the remaining space will be allocated for the first LinearLayout .

    Final layout :

     <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <LinearLayout android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="1"> <ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="right" > <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Btn1" /> <Button android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Рисовать" /> <Button android:id="@+id/btn3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Установки" /> </LinearLayout> </LinearLayout> 
    • It all worked! Many thanks !!! - kaaa