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>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s