2013-11-16 4 views
0
<TextView 
    android:id="@+id/postedBy" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/content" 
    android:layout_marginTop="5dp" 
    android:text="@string/postedBy" 
    android:textColor="#000000" 
    android:textSize="12sp" /> 

<TextView 
    android:id="@+id/username" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_below="@id/content" 
    android:layout_marginTop="5dp" 
    android:textColor="#00aadd" 
    android:textSize="12sp" /> 

Я пытаюсь создать «по имени» в новостной статье, где он должен быть выровнен справа. В этот момент имя пользователя должно быть, но я не могу получить другое текстовое окно слева от него. Примечание: layout_toLeftOf = "@ id/username" не работает.Android TextView align right

Может ли кто-нибудь помочь мне здесь?

Заранее спасибо.

+0

Кто является родителем этих 'TextView's? Это очень важно. Показать полный xml – codeMagic

ответ

0

layout_toLeftOf должен работать внутри RelativeLayout:

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

<TextView 
    android:id="@+id/postedBy" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/content" 
    android:layout_marginTop="5dp" 
    android:text="@string/postedBy" 
    android:textColor="#000000" 
    android:textSize="12sp" 
android:layout_toLeftOf="@+id/username" 
    /> 

<TextView 
    android:id="@+id/username" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_below="@id/content" 
    android:layout_marginTop="5dp" 
    android:textColor="#00aadd" 
    android:textSize="12sp" 
    /> 
</RelativeLayout> 
+0

Это не ответ – codeMagic

+0

Вы правы. Я отредактировал ответ – andrei

+0

Это действительно работает, странно, что это не было при моей попытке, но спасибо! – user2103237