This has had me stumped for a bit and I can’t seem to figure it out.
I am creating a chat interface with side by side relative layouts in a custom adapter.
<?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>
Now, in a layout view everything looks like it would be perfectly fine. But here’s a screenshot of what it looks like on my device:
![enter image description here][1]
The layout on the left sizes the height the way I want it to, but the layout on the right has a big space above it.. Here’s how I’m setting the cell background and resources
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("");
}
Any ideas?
Try removing the
layout_alignParentTopfrom the rightTextView. If that isn’t it, are your background drawables 9-patches? Have you ensured that your 9-patch is correctly stretched?