2013-05-29 5 views
0

Я хочу создать представление с двумя частями: 1. Аватар, который всегда отображается в правом/центральном окне на экране. 2. Имя, которое всегда отображается слева на экране (не перекрывайте аватар).Вид перекрывается другим видом с match_parent и wrap_content на Android

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/username" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@id/avatar" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="right|center_vertical" 
     android:orientation="vertical" > 
     <ImageView 
     android:id="@+id/avatar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right|center_vertical" 
     android:scaleType="center" 
     android:src="@drawable/useravatar" /> 
    </LinearLayout> 
    </LinearLayout> 

Проблема в том, когда имя слишком длинное, оно перекрывается на аватаре. Как я могу исправить эту проблему?

ответ

0

Вы должны использовать RelativeLayout и атрибут android:layout_toLeftOf="@id/avatar" для TextView.

+0

Спасибо за помощь. Он работал нормально. –

+0

@ user2298077, добро пожаловать! Пожалуйста, не забудьте принять ответ, если вы сочтете это полезным. – Egor

0

Вы лучше использовать Relative Layout для этого:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_toLeftOf="@+id/avatar" 
     android:text="Some User Name" /> 

    <ImageView 
     android:id="@+id/avatar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="right|center_vertical" 
     android:scaleType="center" 
     android:src="@drawable/thumbr" /> 

</RelativeLayout> 
+0

Спасибо за помощь. Он работал нормально. –

Смежные вопросы