【发布时间】:2011-03-14 19:00:06
【问题描述】:
我有一个相对布局,其中有两个按钮,分别带有文本“hello”和“world”。我希望这两个按钮彼此相邻,并平等地占据整个可用的水平空间。
我尝试了以下但没有得到预期的输出
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/world" android:id="@+id/world"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/hello"
android:layout_alignTop="@+id/hello"
/>
<Button
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
我尝试将两个孩子的 android:layout_width 更改为 fill_parent 但这也没有用。
我有一个可行的解决方案,即在两个孩子上使用 LinearLayout 并将 layout_weight 设置为 0.5,但我想了解是否有办法在相对布局本身中做到这一点。
谢谢,
【问题讨论】:
-
您似乎已经有了解决方案 - 您到底在寻找什么?
-
使用带有 layout_weight 的 LinearLayout。这是公认的方法。
-
我认为有一个比你选择的更好的答案