2015-05-10 38 views
1

我想做一个聊天室泡泡listview,我遇到了一个问题; 右泡沫布局XML如下如何构建“从右到左”的线性布局?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="end" 
android:orientation="horizontal" > 

<TextView 
    android:id="@+id/textMsg" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<ImageView 
    android:id="@+id/portrait" 
    android:layout_width="40dip" 
    android:layout_height="40dip" /> 

</LinearLayout> 

,结果看起来像图片,为什么它出门左边框的

enter image description here

+2

我们强烈建议您使用TextView来存放**复合可绘制**,而不是使用“TextView/ImageView对”。为**更好的表演** –

回答

1

试试这个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <TextView 
      android:id="@+id/textMsg" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/portrait" 
      /> 

     <ImageView 
      android:id="@+id/portrait" 
      android:layout_width="40dip" 
      android:layout_height="40dip" 
      android:layout_alignParentRight="true" 
      /> 

     </RelativeLayout> 
0

试试这个:只需更改android:layout_width="0dp"并添加android:layout_weight="1"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="end" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/textMsg" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_marginLeft="5dp" 

     /> 

    <ImageView 
     android:id="@+id/portrait" 
     android:layout_width="40dip" 
     android:layout_height="40dip" 
     /> 

</LinearLayout> 
相关问题