2013-07-29 4 views
3

Изображение находится справа от макета. Он не отображается, если содержимое messagedetail_row_text слишком длинное. Изображение показывается, если содержимое messagedetail_row_text не слишком длинное.Почему изображение исчезает на макете?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="15dp" 
    android:gravity="right" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/dfdwasdfds" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/outgoing" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="22dip" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/messagedetail_row_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingTop="1dp" 
       android:textColor="#000000" 
       android:textSize="18sp" /> 

      <TextView 
       android:id="@+id/messagedetail_row_date" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dip" 
       android:paddingTop="1dp" 
       android:textColor="#000000" 
       android:textSize="16sp" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/messagedetail_row_text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="2dp" 
      android:textColor="#000000" 
      android:textSize="20sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_toRightOf="@id/dfdwasdfds" 
     > 

     <ImageView 
      android:id="@+id/messagegedetail_rov_icon2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:gravity="right" 
      android:src="@drawable/retouxiang" /> 

    </LinearLayout> 

</RelativeLayout> 

ответ

1

Попробуйте изменить

<LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_toRightOf="@id/dfdwasdfds" 
      > 


to 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_below="@id/dfdwasdfds" 
     > 
+0

layout_below будет отображать изображение по содержанию, но я просто отобразить изображение справа из содержание. – user2559787

+0

Вы указали свойство width width fill_parent, но макет родителей имеет свойство width width_content, поэтому оно займет пространство справа, когда оно длинное. Никакое пространство для изображения не исчезнет. @ user2559787 –

+0

Вы можете попробовать с фиксированной шириной в родительском макете textView. –

2

Это не ясно, что вы ищете точно. Это от того, что я понимаю:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="15dp" 
    android:gravity="right" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/xyz" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 

     <ImageView 
      android:id="@+id/messagegedetail_rov_icon2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:gravity="right" 
      android:src="@drawable/retouxiang" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/dfdwasdfds" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/xyz" 
     android:background="@drawable/outgoing" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="22dip" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/messagedetail_row_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingTop="1dp" 
       android:textColor="#000000" 
       android:text="messagedetail_row_name" 
       android:textSize="18sp" /> 

      <TextView 
       android:id="@+id/messagedetail_row_date" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dip" 
       android:paddingTop="1dp" 
       android:text="messagedetail_row_date" 
       android:textColor="#000000" 
       android:textSize="16sp" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/messagedetail_row_text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="2dp" 
      android:text="messagedetail_row_text and this is a long text" 
      android:textColor="#000000" 
      android:textSize="20sp" /> 
    </LinearLayout> 

</RelativeLayout> 
0

Я думаю, что это происходит потому, что Вы дали TextView ширину fill_parent и занимает столько места, является его длина, то его родитель ширина wrap_content, поэтому увеличивается до его ребенок занимает пространство (т.е. TextView), поэтому у вас нет места для отображения ImageView.

Вы можете попробовать использовать LinearLayout в качестве корневого макета вместо relativeLayout..and управлять видом давая им вес ..