【发布时间】:2012-01-22 10:12:29
【问题描述】:
我有一个包含一对并排按钮的 RelativeLayout,我希望它们在布局中居中。我可以将按钮放在 LinearLayout 中并在 RelativeLayout 中居中,但我想让我的 xml 尽可能干净。
这是我尝试过的,这只是将“应用”按钮放在中间,将“撤消”按钮放在左边:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15sp">
<TextView
android:id="@+id/instructions"
android:text="@string/instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15sp"
android:layout_centerHorizontal="true"
/>
<Button
android:id="@+id/apply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/apply"
android:textSize="20sp"
android:layout_below="@id/instructions"
/>
<Button
android:id="@+id/undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/undo"
android:textSize="20sp"
android:layout_toLeftOf="@id/apply"
android:layout_below="@id/instructions"
/>
</RelativeLayout>
【问题讨论】: