【发布时间】:2010-11-15 23:30:15
【问题描述】:
我尝试将两个按钮(上面有可以正常工作的图像)排列在一起,并将它们水平居中。这就是我目前所拥有的:
<LinearLayout android:orientation="horizontal" android:layout_below="@id/radioGroup"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center">
<Button
android:id="@+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/radioGroup"
android:layout_gravity="center_horizontal"
android:drawableLeft="@drawable/accept_btn"
android:text="Allow"/>
<Button
android:id="@+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/allow"
android:layout_below="@id/radioGroup"
android:layout_gravity="center_horizontal"
android:drawableLeft="@drawable/block_btn"
android:text="Deny"/>
</LinearLayout>
不幸的是,它们仍然与左侧对齐。任何帮助表示赞赏!伊夫
编辑:
不幸的是,到目前为止,没有任何 cmets 或建议起作用。这就是为什么我现在尝试使用 RelativeLayout 来提供简化的完整布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button
android:id="@+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/TextView01"
android:text="Allow"/>
<Button
android:id="@+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/allow"
android:layout_alignTop="@id/allow"
android:text="Deny"/>
</RelativeLayout>
我已经尝试了 LinearLayout 和 Button 元素中的所有属性组合,但没有运气。还有其他想法吗?
【问题讨论】:
-
按钮有多大?它们会像您想要的那样并排放置吗?
-
是的,这完全没有问题。目前它们并排出现,但它们坚持在左侧。
-
哦,我明白你的问题是什么了,我看错了问题。我以为你是说你不能让它们水平排列。