2012-08-06 36 views
4

我需要將一個ImageView和TextView放在一個RelativeLayout中。 我無法弄清楚我做錯了什麼。Centre RelativeLayout

這裏是我的代碼:

<RelativeLayout  
     android:id="@+id/teamNameLayout" 
    android:layout_width="130dip" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal"   
    android:background="@drawable/border" 
    android:layout_toLeftOf="@+id/teamPosition"   
    > 
    <ImageView 
      android:id="@+id/teamIcon" 
      android:src="@drawable/logo1" 
      android:layout_width="20dip"    
      android:layout_height="fill_parent"      
      android:scaleType="fitXY" 
      android:textStyle="bold" 
     android:textSize="16sp" 
      /> 
    <TextView android:id="@+id/teamName" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center"       
     android:textColor="#000000" 
     android:textStyle="bold" 
     android:textSize="16sp"  
     android:text="blabla" /> 
    </RelativeLayout> 

我已經試過了 「CENTER_HORIZONTAL」,但沒有成功。 我需要ImageView將在TextView的右側。

+1

是否要將ImageView和TextView組合到視圖的中心? – 2012-08-06 11:55:29

+0

是的。而且我還需要爲imageview中的textview填充內容。 – ohadinho 2012-08-06 12:13:36

+0

RelativeLayout沒有方向btw – banzai86 2012-08-06 12:41:13

回答

9

我試過「center_horizo​​ntal」沒有成功。我需要 ImageView將位於TextView的右側。

=>嘗試android:layout_centerInParent="true"爲您的TextView,並在您的ImageView中使用android:layout_toRightOf="@+id/teamName

+0

謝謝,這是有效的。如果我還需要從imageview的textview填充? – ohadinho 2012-08-06 12:14:08