开发者

Android UI - align buttons in the centre, order vertically

开发者 https://www.devze.com 2023-04-11 10:08 出处:网络
I\'m trying to create a UI that has a banner on the top but one table row below has a list of buttons ordered vertically, but aligned horizontally...

I'm trying to create a UI that has a banner on the top but one table row below has a list of buttons ordered vertically, but aligned horizontally...

My code so far is...

<?xml version="1.0" encoding="utf-8"?>

<Button android:id="@+id/button1" android:layout_height="wrap_content" 
android:layout_width="wrap_content" android:text="Theme">
</Button>

<Button android:id="@+id/button1" android:layout_height="wrap_content" 
android:layout_width="wrap_content" android:text="Theme2">
</Button>

<Button android:id="@+id/button1" android:layout_height="wrap_content" 
android:layout_width="wrap_content" android:text="Theme3">
</Button>

All this does is put all the buttons in the centre, ho开发者_运维技巧w do I make each button flow down? I basically want a similar UI design to http://www.appbrain.com/app/friday-soundboard-rebecca/com.randomcrap.soundboard


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button android:text="Button" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/button1"
        android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></Button>
    <Button android:text="Button" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/button2"
        android:layout_below="@+id/button1" android:layout_centerHorizontal="true"></Button>
    <Button android:text="Button" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/button3"
        android:layout_below="@+id/button2" android:layout_centerHorizontal="true"></Button>
    <Button android:text="Button" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/button4"
        android:layout_below="@+id/button3" android:layout_centerHorizontal="true"></Button>
</RelativeLayout>


you have to use android:layout_weight="1" on all the buttons for making them in the center . Also make all the android:gravity and android:layout_gravity at "center" and for the spacing stuff use

padding-left="20dp"
padding-right="20dp"
padding-top="5dp"
paddding-bottom="5dp"

i think this all should work !

0

精彩评论

暂无评论...
验证码 换一张
取 消