vendredi 31 octobre 2014

Arrange buttons centrally in screen below title TextView in Android Layout


Vote count:

0




I am trying to arrange 3 buttons vertically in the centre of the available space in an Android Activity. I also have a title field in a TextView and I need this to be at the top of the display screen with a vertical gap between it and the buttons. I also need the blank space between the bottom button and the bottom of the screen to be the same as the space between the top button and the bottom of the TextView.


From reading the docs istm that a pair of nested vertical LinearLayouts should do the job as below but this leaves me with the buttons arranged immediately following the TextView with no space between the TextView and the top button.


Any ideas how I can achieve my aim would be gratefully received.



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView android:id="@+id/app_title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_title_label"
android:gravity="top"
style="?android:listSeparatorTextViewStyle"
/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center" >

<Button android:id="@+id/button_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>

<Button android:id="@+id/button_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>

<Button android:id="@+id/button_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>

</LinearLayout>

</LinearLayout>


Thanks,



asked 24 secs ago

Boo

8






Arrange buttons centrally in screen below title TextView in Android Layout

Aucun commentaire:

Enregistrer un commentaire