Here is how to center 2 buttons inside a layout. These do not have to be buttons but can be any type of view. The idea behind it is to create a layout and add two horizontal Linear Layout inside and assign the same weight to both. When the buttons are inside then center the buttons inside the layout. Since each layout is set to ‘match_parent’ then it will scale to any screen size.
Here is the idea of centering two views inside a layout:
Here is the code:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" > <Button android:id="@+id/cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="18dp" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" android:layout_weight="1" > <Button android:id="@+id/continue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"/> </LinearLayout> </LinearLayout>
thank you, I needed that and it’s very well explained.