Android用户界面 - 对齐中心的按钮,垂直排列

问题描述:

我试图创建一个界面上有一个横幅的界面,但下面的一个表格列有一个垂直排列的按钮列表,但水平排列...Android用户界面 - 对齐中心的按钮,垂直排列

我的代码到目前为止...

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

所有这些都会将所有按钮放在中间,我如何让每个按钮向下流动?我基本上要一个类似的UI设计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> 
+0

嗯,感谢你这样做,垂直对齐的作品,但按钮没有对齐在左上角的中心,任何想法? – david99world

+0

检查一下它的工作很好,,,,,,,,,,,,, –

你必须使用所有的按钮android:layout_weight="1" 为使他们在中心。 另外,还要在“中心” 所有android:gravityandroid:layout_gravity和间距的东西 使用

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

我想这一切应该努力!