1

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.

2
  • 1
    Post your code, then we can suggest you after watching your effort (and other design). Commented Aug 4, 2012 at 10:27
  • Just do some google work and learn to create buttons. Do some trials and then post your question here. Start from here : androidpeople.com/button HOpe it will help you to learn the basics
    – Dray
    Commented Aug 4, 2012 at 10:31

4 Answers 4

1

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>
1

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>
1

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>
1
<?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>    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.