2014-01-30 47 views
0

我有以下XML:中心SeekBar和ImageButton的在RelativeLayout的

<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

你在哪裏應用了layout_gravitiy屬性? – Blackbelt

+0

On'RelativeLayout' – Nfear

+1

layout_gravity將在其父項中設置RelativeLayout的重力。 – Blackbelt

回答

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> 
相關問題