2016-02-05 75 views
0

我有TextView与android android:layout_centerHorizontal="true",其中是用户昵称和TextView.I的权利要添加一个ImageView,我设置用户的状态(红色或绿色),但状态图像仍处于左侧(已设置layout_toEndOf="@+id/username")。Android的ImageView中的TextView与layout_centerHorizo​​ntal =“true”

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:text="@string/username" 
    android:id="@+id/username" 
    android:layout_alignParentTop="false" 
    android:textColor="#921090" 
    android:textSize="20dp" 
    android:layout_centerHorizontal="true"/> 

<ImageView 
    android:layout_width="10dp" 
    android:layout_height="10dp" 
    android:id="@+id/status" 
    android:layout_toEndOf="@+id/username" 
    android:layout_alignParentTop="true" 
    android:layout_toRightOf="@+id/username"/> 
+0

'机器人:layout_toLeftOf =“@ ID/status“'添加此Textview部分 –

+0

改为使用线性布局。你的问题将解决 –

+0

尝试从'ImageView'中删除'layout_alignParentTop' – camelCaseCoder

回答

0

请试试这个。

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 

     <TextView 
      android:id="@+id/username" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="name" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="#921090" 
      android:textSize="20dp" /> 

     <ImageView 
      android:id="@+id/status" 
      android:layout_width="10dp" 
      android:layout_height="10dp" 
      android:layout_marginLeft="10dp" /> 

</LinearLayout> 
+0

http://screencloud.net/v/DPBm android:layout_centerInParent =“true”它不是从那里!我需要使用RelativeLayout,因为它的布局更复杂,它是一个

+0

这是什么? @FedotSerghei –

+0

这是一个用户名的个人资料视图! –

0

已尝试android:weightSum,因此它将在所有具有diffrenet分辨率的设备中受支持。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:weightSum="2"> 

    <TextView 
     android:id="@+id/username" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/username" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#921090" 
     android:textSize="20dp" /> 

    <ImageView 
     android:id="@+id/status" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/cal" /> 

</LinearLayout> 

+0

是你的问题解决? @Fedot Serghei –

0

这里是您的解决方案

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TextView 
     android:id="@+id/username" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="false" 
     android:text="username" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#921090" 
     android:paddingEnd="10dp" 
     android:textSize="20dp" /> 

    <ImageView 
     android:id="@+id/status" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:layout_alignParentTop="true" 
     android:layout_toEndOf="@+id/username" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

希望对您有所帮助,......

相关问题