0

我正在开发一个消息应用程序,遇到了一个小问题,但非常烦人。我通过引入布局然后膨胀来即时渲染消息。这部分工作正常。问题是,假设我有一条消息比另一条消息短,较小的消息不会保留布局以确保其大小与较大的消息相同。

我的布局文件看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="horizontal"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="fill_parent"
p1:layout_height="fill_parent"
p1:id="@+id/linearLayout1">
<LinearLayout
    p1:orientation="horizontal"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="fill_parent"
    p1:layout_height="wrap_content"
    p1:id="@+id/linearLayout9"
    p1:weightSum="1">
    <LinearLayout
        p1:orientation="vertical"
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="wrap_content"
        p1:layout_height="fill_parent"
        p1:id="@+id/linearLayout10"
        p1:layout_weight=".15" />
    <LinearLayout
        p1:orientation="vertical"
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="match_parent"
        p1:layout_height="fill_parent"
        p1:id="@+id/linearLayout11"
        p1:layout_weight=".7"
        p1:weightSum="1"
        p1:background="@drawable/border">
        <LinearLayout
            p1:orientation="horizontal"
            p1:minWidth="25px"
            p1:minHeight="25px"
            p1:id="@+id/linearLayout2"
            p1:layout_width="match_parent"
            p1:layout_height="wrap_content"
            p1:weightSum="1">
            <LinearLayout
                p1:orientation="vertical"
                p1:minWidth="25px"
                p1:minHeight="25px"
                p1:layout_width="match_parent"
                p1:layout_height="fill_parent"
                p1:id="@+id/linearLayout3">
                <TableLayout
                    p1:minWidth="25px"
                    p1:minHeight="25px"
                    p1:layout_width="fill_parent"
                    p1:layout_height="wrap_content"
                    p1:id="@+id/tableLayout1">
                    <TableRow
                        p1:id="@+id/tableRow1"
                        p1:weightSum="1">
                        <LinearLayout
                            p1:orientation="horizontal"
                            p1:minWidth="25px"
                            p1:minHeight="25px"
                            p1:id="@+id/linearLayout5"
                            p1:layout_weight=".8"
                            p1:background="@drawable/border"
                            p1:layout_width="match_parent">
                            <TextView
                                p1:textAppearance="?android:attr/textAppearanceLarge"
                                p1:layout_width="match_parent"
                                p1:layout_height="fill_parent"
                                p1:id="@+id/textFrom"
                                p1:layout_marginLeft="5dp"
                                p1:layout_marginRight="5dp"
                                p1:textColor="#000" />
                        </LinearLayout>
                        <LinearLayout
                            p1:orientation="vertical"
                            p1:minWidth="25px"
                            p1:minHeight="25px"
                            p1:id="@+id/linearLayout4"
                            p1:layout_weight=".2"
                            p1:background="@drawable/border">
                            <LinearLayout
                                p1:orientation="horizontal"
                                p1:minWidth="25px"
                                p1:minHeight="25px"
                                p1:id="@+id/linearLayout7"
                                p1:layout_width="match_parent"
                                p1:layout_height="wrap_content">
                                <TextView
                                    p1:textAppearance="?android:attr/textAppearanceSmall"
                                    p1:layout_width="match_parent"
                                    p1:layout_height="fill_parent"
                                    p1:id="@+id/textDate"
                                    p1:gravity="top"
                                    p1:textColor="#000" />
                            </LinearLayout>
                            <LinearLayout
                                p1:orientation="horizontal"
                                p1:minWidth="25px"
                                p1:minHeight="25px"
                                p1:layout_width="match_parent"
                                p1:layout_height="wrap_content"
                                p1:id="@+id/linearLayout8">
                                <TextView
                                    p1:textAppearance="?android:attr/textAppearanceSmall"
                                    p1:layout_width="match_parent"
                                    p1:layout_height="fill_parent"
                                    p1:id="@+id/textTime"
                                    p1:gravity="top"
                                    p1:textColor="#000" />
                            </LinearLayout>
                        </LinearLayout>
                    </TableRow>
                </TableLayout>
                <LinearLayout
                    p1:orientation="horizontal"
                    p1:minWidth="25px"
                    p1:minHeight="25px"
                    p1:layout_width="fill_parent"
                    p1:layout_height="wrap_content"
                    p1:id="@+id/linearLayout6"
                    p1:background="@drawable/border"
                    p1:layout_weight="1">
                    <TextView
                        p1:textAppearance="?android:attr/textAppearanceMedium"
                        p1:layout_width="match_parent"
                        p1:layout_height="fill_parent"
                        p1:id="@+id/textMessage"
                        p1:layout_marginLeft="5dp"
                        p1:layout_marginRight="5dp"
                        p1:textColor="#000" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        p1:orientation="vertical"
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="wrap_content"
        p1:layout_height="fill_parent"
        p1:id="@+id/linearLayout12"
        p1:layout_weight=".15" />
</LinearLayout>
</LinearLayout>

边框文件是这个

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <stroke android:width="1dip" android:color="@android:color/transparent"/>
</shape>

无论消息大小如何,如何确保布局保持不变有什么想法吗?

谢谢

4

0 回答 0