0

我正在尝试构建和显示有组织的数据的应用程序,所以我认为基本上TableLayout是一个好主意,只是将它们保持在行中,所以我想知道正确的方法是什么?我的xml中有这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TableRow>
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="@string/hello" >
             </TextView>

            <ListView
                android:id="@+id/listView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="233dp"
                android:layout_marginTop="44dp" >
            </ListView>
        </TableRow>
    </TableLayout>

</LinearLayout>

那么只是TableLayout标签和TableRow标签显示一个警告,上面写着:

"This TableLayout layout or its LinearLayout parent is possibly useless"

所以我的理解是没有拿起TableLayout. 我怎样才能解决这个问题?还有其他方法可以轻松做到这一点吗?

4

3 回答 3

1

所以我的理解是没有拿起表格布局。我怎样才能解决这个问题?还有其他方法可以轻松做到这一点吗?

不完全是,渲染器正在考虑 TableLayout 但是因为当您只需要一个(A和)时该lint工具检测到您有两个视图,它警告您应该删除其中一个布局,因为它会提高性能而不是影响页面的功能。LinearLayoutTableLayout

我要补充一点,你有一个只有一行的 TableLayout。TableLayout 的设计目的是允许它们的内容根据它们的所有行来格式化它们的列。使用单个 Row,TableLayout 和 Row 一起充当 LinearLayout:

<LinearLayout>
    <LinearLayout>
        <ListView>
        <TextView>

由于您的 TableLayout 在这种情况下没有添加任何附加布局,因此它变得过时了,您将通过删除它并将orientationLinearLayout 更改为horizontal.

如果您打算TableRow稍后添加更多 ,那么您应该LinearLayout出于同样的原因删除 —— 然后它将成为不添加额外信息的视图:您的表格布局将完全负责布局,因此您可以让它成为布局文件的父级(xmlns:android="http://schemas.android.com/apk/res/android"如果你这样做,请记住向它添加属性。)

于 2012-02-10T14:59:42.570 回答
1

总的来说,我看到了更强烈的警告:

这个 LinearLayout 布局或者它的 RelativeLayout 父级是没用的

当情况并非如此。例如,如果我在相对布局中嵌套了线性布局,就会发生这种情况。相对布局将线性布局准确定位在我想要的位置,线性布局占用空间。两者对我来说都是无用的。

于 2012-02-12T13:49:31.597 回答
0

1)它说可能避免得出结论,相信自己年轻的padawan!但是,是的,父母对我来说也没什么用:)

2)在您不会更改列表中行的布局之外使用表格布局ListView,以防这是您想要实现的。

您可能已经看到了,但开发人员页面提供了一个非常好的教程,可以帮助您为您的ListView(本示例使用ListActivity) 创建一个良好的基础。TableLayout然后,您可以使用...等修改行的布局。

于 2012-02-10T14:44:44.930 回答