我使用下面发布的布局通过将该布局作为一行扩展到 ListView 中来显示消息。问题是它可以很好地处理单行消息,但是当有 2 行或更多行时,指示消息状态的 ImageView
被推离屏幕,无法找到原因。有任何想法吗?布局代码和屏幕截图如下。
那是膨胀的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp" >
<TextView
android:id="@+id/tvTimestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="8sp" />
<LinearLayout
android:id="@+id/rl_message_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toRightOf="@+id/tvTimestamp"
android:background="@drawable/outgoing_bg"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvMessageOutgoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imgMessageState"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>
最佳答案
改变你的线性布局宽度 fill_parent
并在 TextView 中添加 android:layout_weight="1"
关于android LinearLayout - ImageView 被推离屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14622505/