1

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!

1 Answer 1

1

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!]   |
|                      |
|                      |
|______________________|
0

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.