2012-08-06 73 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