android:layout_weight

Only in LinearLayout

We have a LinearLayout with Horizontal orientation, and a EditText, a Button inside.

  1. If we want both the EditText and the Button take half width of the screen, set both of them:

     
    x
    android:layout_width="0dp"
    android:layout_weight="1"

  2. The EditText take 2/3, and the Button take 1/3 of the screen,

    In EditText:

     
    x
    android:layout_width="0dp"
    android:layout_weight="2"

    In Button:

     
    xxxxxxxxxx
    android:layout_width="0dp"
    android:layout_weight="1"