2015-08-14 72 views
-1

我想在Android中创建一个简单的布局。基本上我的大矩形应该是水平和垂直居中。小按钮垂直定位在屏幕底部和屏幕中心之间等距离并水平居中。 reference在Android中使用LinearLayout设置两个对象

大矩形的外形尺寸是354×168 小矩形的外形尺寸是124x48

我应该使用线性布局或相对布局?我将不胜感激任何帮助。

+0

让我们了解您到目前为止试过。 – Squonk

回答

1

试试这个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="100dp" 
     android:layout_height="30dp" 
     android:layout_centerInParent="true" 
     android:background="#000" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/button1" > 
     <Button 
     android:id="@+id/button2" 
     android:layout_width="60dp" 
     android:layout_height="20dp" 
     android:layout_centerInParent="true" 
     android:background="#000" /> 
    </RelativeLayout> 

</RelativeLayout> 
+0

谢谢Aakash,我有一个类似的布局,但我没有使用第二个RelativeLayout。不过,我的问题是,即使设置宽度和高度,我的图像也会放大。这是正常的吗? – ilteris

+0

我将它们设置为“pt”而不是“dp”,这可能是问题所在吗? – ilteris

+0

dp是首选,因为它根据不同的屏幕尺寸调整 – Aakash

相关问题