代码之家  ›  专栏  ›  技术社区  ›  Ian Leslie

为什么我的水平线布局没有为其内容保留足够的高度?

  •  1
  • Ian Leslie  · 技术社区  · 15 年前

    我正在开发一个显示世界各国信息的应用程序(我正在学习一些真实的东西,我已经有了这些数据)。我的部分布局是一个线性布局,其中包含国家的国旗和一些基本信息。在标志右边的表中有五行信息。问题是线性布局仅使用标志的高度作为其总高度。大多数标志的高度是2.5行,因此我的一些信息被切断。为什么linierlayout的高度不是它的两个元素中最大的?有什么建议可以让我做这个工作吗?

    以下是有关线性布局的定义:

            <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
            <ImageView
                android:id="@+id/flag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/noflag" />
            <TableLayout
                android:id="@+id/info1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_marginLeft="10dip">
                <TableRow>
                    <TextView
                        android:id="@+id/capitallabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/capital_label"
                        style="?infoLabel"/>
                    <TextView
                        android:id="@+id/capitalvalue"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dip"
                        style="?infoValue"/>
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/capitaltimelabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/capital_time_label"
                        style="?infoLabel"/>
                    <TextView
                        android:id="@+id/capitaltimevalue"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dip"
                        style="?infoValue"/>
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/landarealabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/land_area_label"
                        style="?infoLabel"/>
                    <TextView
                        android:id="@+id/landareavalue"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dip"
                        style="?infoValue"/>
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/waterarealabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/water_area_label"
                        style="?infoLabel"/>
                    <TextView
                        android:id="@+id/waterareavalue"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dip"
                        style="?infoValue"/>
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/coastlinelabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/coast_line_label"
                        style="?infoLabel"/>
                    <TextView
                        android:id="@+id/coastlinevalue"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="4dip"
                        style="?infoValue"/>
                </TableRow>
            </TableLayout>
        </LinearLayout>
    

    我试着把桌子和图像视图颠倒过来,这样旗帜就在右边,信息就在左边。我希望现在的linearlayout的高度是信息表的高度。不走运,还是国旗的高度。

    任何帮助都将不胜感激。

    谢谢,

    伊恩

    1 回复  |  直到 15 年前
        1
  •  1
  •   CommonsWare    15 年前

    尝试 android:layout_height="wrap_content" 为了你的 TableLayout .