【发布时间】:2011-08-23 10:28:58
【问题描述】:
这让我有些困惑,我似乎无法弄清楚。
我正在自定义适配器中创建一个具有并排相关布局的聊天界面。
<?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("");
}
有什么想法吗?
【问题讨论】: