我有以下xml:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/reset"
android:src="@drawable/ic_action_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset"
android:onClick="reset"
android:layout_alignParentRight="true" />
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/reset" />
</RelativeLayout>
我尝试使用gravity="center"
和layout_gravity="center"
但它没有用。如何使RelativeLayout的内容居中?
答案 0 :(得分:0)
您可以使用这三种中的一种进行相对布局:
答案 1 :(得分:0)
使用以下代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/reset"
android:src="@drawable/ic_action_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset"
android:onClick="reset"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true" />
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/reset"
android:layout_centerHorizontal="true" />
</RelativeLayout>