2013-08-29 56 views
1


任何人都知道如何在另一個視圖的中間設置視圖(按鈕)?例如,我想要在頂部的兩個按鈕或按鈕連接的中間進行調整。我presice有東西在我父視圖,所以我不能與佈局對齊的左邊,感謝
我有什麼:
enter image description here在android xml的其他視圖的中間設置視圖

我想要什麼:

enter image description here

+0

你能發佈你的xml代碼嗎? –

+0

你能澄清你的問題併發布你的XML嗎? –

回答

4

將兩個按鈕都放在LinearLayout之內。 LinearLayout's方向應該是horizontal。給予1的每個按鈕layout_weight。例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 

</LinearLayout> 
1

如果您使用的是LinearLayout,您可以將其設置爲android:gravity="center"(或者只需要您的需求爲android:gravity="center_vertical")。

如果您使用的是RelativeLayout,那麼您可以通過使用layout_alignParentBottomlayout_centerHorizontal,...和其他attrs來設置視圖。

我不是很確定你想把兩個按鈕放在哪裏,如果仍然無法解決,請嘗試上面的解決方案並提供更多的細節(也許你當前的XML)。

+0

我添加圖片更清晰 – Armanoide

+0

代碼!有很多方法可以做到這一點 –

相關問題