这让我有点困惑,我似乎无法弄清楚。
我正在自定义适配器中创建一个并排相对布局的聊天界面。
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_weight="1" android:layout_height="wrap_content">
<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content">
<TextView android:id="@+id/lefttext" android:text="TextView" android:layout_width="fill_parent" android:gravity="top" android:layout_height="wrap_content" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="5dip" android:layout_alignParentLeft="true"></TextView>
</RelativeLayout>
<RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content">
<TextView android:id="@+id/righttext" android:layout_width="fill_parent" android:text="TextView" android:layout_height="wrap_content" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="5dip" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"></TextView>
</RelativeLayout>
</LinearLayout>
现在,在布局视图中,一切看起来都很好。但这是它在我的设备上的外观的屏幕截图:
![在此输入图像描述][1]
左边的布局按照我想要的方式调整了高度,但右边的布局上面有一个很大的空间。以下是我设置单元格背景和资源的方法
if (wasMine == 0)
{
lt.setText(Message);
leftLayout.setBackgroundResource(R.drawable.speechbubblefrom);
rightLayout.setBackgroundDrawable(null);
rt.setText("");
}
else if (wasMine == 1)
{
rt.setText(Message);
rightLayout.setBackgroundResource(R.drawable.speechbubbleto);
leftLayout.setBackgroundDrawable(null);
lt.setText("");
}
有什么想法吗?
尝试从右侧TextView
中删除layout_alignParentTop
。如果不是这样,您的背景可绘制对象是 9 个补丁吗?您是否确保 9 补丁被正确拉伸?