这个任务很简单:有两个按钮和一个上面的TextView
。所有的小部件都应该在相对布局中居中。我唯一的想法是创建第三个部件View
并将其用作按钮的中心轴。有任何想法吗?冗余布局不是一个好的解决方案。如何在相对布局中居中两个视图?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/app_name" />
<View
android:id="@+id/view_axis"
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_below="@id/tv_progress"
android:layout_centerInParent="true" />
<Button
android:id="@+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_progress"
android:layout_toLeftOf="@id/view_axis"
android:text="@string/start" />
<Button
android:id="@+id/button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_progress"
android:layout_toRightOf="@id/view_axis"
android:text="@string/stop" />
</RelativeLayout>
看看这里,这个答案,该答案打勾没有什么最初问。 http://stackoverflow.com/questions/10904864/relativelayout-gravity-center-not-working/13280255#13280255 – user1806772