2015-06-04 38 views
0

嘿Guyz幫助我我陷入了一個對齊設置問題...我是Android開發新手,我想實現的目標是我製作一個音樂播放器,其中我想設置一個ImageView的一個ImageButton的,但我想設置它的中心是什麼,我沒有發現任何低於辦法是我試過的代碼..兩個控制器是否可以有相同的中心

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <ImageButton 
     android:alpha="50" 
     android:id="@+id/imageView1" 
     android:layout_width="115dp" 
     android:layout_height="115dp" 
     android:padding="6dp" 
     android:src="@drawable/play_btn" 
     android:background="@null" 
     /> 
    <ImageView 

     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:src="@drawable/Artist" 
     android:layout_above="@+id/textView2" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

這是我試過,但我找不到像 alignWithMatchCenter =「父ID」或centerInParent =「父ID」

或有可能,如果我可以添加ImageView機智hin ImageButton標籤?

<ImageButton 
     android:layout_width="115dp" 
     android:layout_height="115dp" 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageView" 
      android:src="@drawable/Artist" 
      android:layout_above="@+id/textView2" 
      android:layout_centerHorizontal="true" /> 
     /> 

請幫我朋友。 任何幫助將不勝感激。 問候, Sarosh斑

+0

**「......我想把它放在中心......」**:我不明白你的意思。你是說你想讓'ImageView'覆蓋'ImageButton'嗎? – Squonk

+0

是的,我希望兩個控制器的中心都是相同的。 –

回答

0

您正在尋找這樣的事情:

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageButton 
     android:id="@+id/imageView1" 
     android:alpha="50" 
     android:layout_width="115dp" 
     android:layout_height="115dp" 
     android:padding="6dp" 
     android:src="@drawable/play_btn" 
     android:layout_centerInParent="true"/> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/Artist" 
     android:layout_centerInParent="true" /> 

</RelativeLayout> 

您可以使用android:layout_centerInParent="true"居中一個孩子。您也可以使用FrameLayout並設置android:layout_gravity="center"

相關問題