I have this layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="32dp">
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Button1"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Button2"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Button3"/>
</LinearLayout>
I want to align horizontally these 3 fix width buttons. Could you help me please ?
Basically there are 3 steps involved.
Set weightSum="3" to the parent layout. This means that the sum of the entire layout_weights is 3.
Set layout_weight="1" to each of the individual buttons. So each individual button has 1/3rd the size of the parent.
Finally set layout_width="0dp", this is important because here you don't have to set the width of the view. It will be set automatically by the layout handler.