I have two buttons. I want to align them at the center of the screen,. I tried doing.. but i'm not able to do it.
fragment_main.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.assignment_1.MainActivity$PlaceholderFragment" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button1"
android:id="@+id/button1"
android:onClick="Display"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:text="@string/button2"
android:id="@+id/button2"
android:onClick="opaquemessage"/>
<TextView
android:id="@+id/display_mes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
You just add this line into your button that's all.... This one is for your Relative layout
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
suppose you will use the linear layout means use this below
android:layout_gravity="center"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments