I have 4 buttons that I space out evenly using layout_weight="1" and layout_width="0dp". However, on large tablet layouts the buttons are too spread out and looks ugly, so I want to set a maxWidth for all of them, and having empty spaces on both sides of the entire LinearLayout instead (so the four buttons are clustered to the center). However, crawling through StackOverflow, many say they don't work together. Is there a way for me to achieve what I want to do above?
tl;dr:
- Below a certain width (say, 100dp), all 4 buttons are spaced evenly.
If layout requires buttons to be bigger than 100dp, all 4 buttons are set to 100dp width and stick together, leaving space on both sides of the layout.
<LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/layout_height" android:background="@drawable/layout_background" android:orientation="horizontal"> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> </LinearLayout>