2012-07-26 51 views
0

我想打一个布局充满了这样的按钮:如何在不同的屏幕android中安排小部件?

enter image description here

我用表格布局试过,但我不能得到正确的空间按钮之间,还当我在不同的屏幕上尝试大小,一切都搞砸了(即使当我使用android:layout_weight),所以现在我用相对布局,但我不能让按钮在屏幕更改时采取正确的大小,我已阅读关于处理不同屏幕的提示大小,所以我使用dp和wrap_content,但没有任何工作,这里是我的代码:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

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

     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 

     android:layout_marginLeft="24dp" 
     android:layout_marginTop="31dp" 
     android:layout_marginRight="150dp" 

     android:background="@layout/press" 
     android:drawableTop="@drawable/reading" 
     android:text="@string/option" /> 

    <Button 
     android:id="@+id/Button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/button1" 
     android:layout_alignBottom="@+id/button1" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="28dp" 

     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="150dp" 

     android:background="@layout/press" 
     android:drawableTop="@drawable/reading" 
     android:text="@string/option" /> 
</RelativeLayout> 

我打算设置第一排按钮,但Button2不会调整它应该是的,我做错了什么?或者我该如何做到这一点? 谢谢。

回答

0

试试这个。

<LinearLayout 
android:orientation = "vertical"> 


<LinearLayout 
android:orientation = "horizontal"/> 

2 Buttons here. 
</LinearLayout> 
</LinearLayout> 

不要忘记包含线性布局的高度和宽度。希望这可以帮助。

+0

实际上在我的主线性布局中我有我发布的代码 – 2012-07-26 21:28:13

+0

您是否收到错误?尝试将RelativeLayout替换为LinearLayout。或者你也可以尝试在你的RelativeLayout下创建一个LinearLayout。 – JetPro 2012-07-26 21:34:01

+0

我没有收到错误,问题在于Button2没有调整大小,因为它应该在另一个屏幕大小 – 2012-07-26 21:37:08