【问题标题】:Android layout - two relative layouts with similar properties, but the second one is bigger in a rowAndroid 布局 - 两个具有相似属性的相对布局,但第二个连续较大
【发布时间】: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("");
            }

有什么想法吗?

【问题讨论】:

    标签: java android xml layout


    【解决方案1】:

    尝试从右侧TextView 中删除layout_alignParentTop。如果不是这样,您的背景可绘制对象是 9 补丁吗?你确定你的 9-patch 被正确拉伸了吗?

    【讨论】:

    • 哇,最终成为 9 补丁图像。谢谢!
    • 优秀。它们很强大,但如果你不小心,可能会让人头疼。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多