2015-08-14 77 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

相關問題