I'm new to android programming. i'm making an application, in this i want text and button in the center of my screen.
But i can't know how to this.
Thanks in advance.
I'm new to android programming. i'm making an application, in this i want text and button in the center of my screen.
But i can't know how to this.
Thanks in advance.
Try this layout
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
andriod:text="Test"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
andriod:text="Button"/>
</LinearLayout>
Yes you can do this if your parrent layout is Relative Layout.
example is :
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/mBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Button!"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/mTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text"Some Text"
android:layout_above="@+id/mBtn" />
</RelativeLayout>
Try this way
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignLeft="@+id/button1"
android:layout_marginBottom="17dp"
android:text="TextView" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="This is button"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Text data dayay"
android:layout_above="@+id/button" />
</RelativeLayout>