2013-08-29 86 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

代码!有很多方法可以做到这一点 –

相关问题