Mobie
Mobie

Reputation: 1900

Positioning of textview for Android

Is there a way to position a textview to be slightly above a centerd android button? I don't want to hardcode values for a particular screen obviously, but something that will dynamically scale. The button will always be centered, however...

Thanks in advance!

Upvotes: 1

Views: 62

Answers (1)

FoamyGuy
FoamyGuy

Reputation: 46846

Yes if your parent layout is a RelativeLayout you can position Views in relation to each other or to the parent here is a simple example (Warning didn't type this into IDE, may contain typo):

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

That will make your layout look roughly like this:

________________________
|                      |
|                      |
|      Some Text       |
|   [I am a Button!]   |
|                      |
|                      |
|______________________|

Upvotes: 1

Related Questions