How to evenly show two buttons side by side (Horizontally) in Android Layout

Android Layouts are very easy to understand but you need to dig down and some easy things becomes a little difficult. I need to have two buttons side by side and it should adapt itself in any device means that the width needs to expand and fit on the screen. Tested the below code to get the desired output.

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”horizontal”
tools:context=”.MainActivity” >

<Button
android:id=”@+id/button5″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:text=”Button” />

<Button
android:id=”@+id/button2″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:text=”Button” />
</LinearLayout>

Leave a comment