Android-tableLayout中的列表视图

Android-tableLayout中的列表视图,android,android-layout,android-listview,android-ui,android-tablelayout,Android,Android Layout,Android Listview,Android Ui,Android Tablelayout,我正在尝试构建和应用程序来显示有组织的数据,所以我认为基本上一个表格布局将是一个好主意,只是将它们保持成行,所以我想知道正确的方法是什么?我的xml中有这个 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" androi

我正在尝试构建和应用程序来显示有组织的数据,所以我认为基本上一个
表格布局将是一个好主意,只是将它们保持成行,所以我想知道正确的方法是什么?我的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>
因此,我所理解的是,这并不是在选择
表格布局
。我怎样才能解决这个问题?有没有其他方法可以轻松做到这一点?

1)上面说可能是这样的避免得出结论,相信你自己,年轻的学徒!但是是的,父母对我来说也没用:)

2) 在
列表视图之外使用表布局
不会改变列表中的行布局,以防这是您想要实现的

您可能已经看到了这一点,但是可以帮助您为
列表视图
(此示例使用
列表活动
)创建一个良好的基础。然后,您可以使用
TableLayout
…等修改行的布局

因此,我的理解是,这不是拿起桌面布局。我怎样才能解决这个问题?有没有其他方法可以轻松做到这一点

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

我要补充的是,你有一个只有一行的表格布局。TableLayout的设计允许其内容根据其所有行格式化其列。对于单行,TableLayout和Row一起充当线性布局:

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

由于您的TableLayout没有添加任何附加布局,在这种情况下,它将过时,您可以通过删除它并将LinearLayout的
方向更改为
水平方向来获得资源提升


如果您计划在以后添加更多的
TableRow
,那么您应该删除
LinearLayout
,因为同样的原因-它将成为不添加额外信息的视图:您的表布局将完全负责布局,因此您不妨将其作为布局文件的父级(请记住添加
xmlns:android=”http://schemas.android.com/apk/res/android“
属性,如果您这样做。)

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

此LinearLayout布局或其相对layout父级无效


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

wow man,感谢您提供的信息,非常有启发性,我会这样做,然后看看结果如何,但是另一件事,如果我想在以后添加更多的行,比如说数据库中的信息,最好是通过编程方式添加行,或者在xml文件中设置布局?如果要提取数量可变的行,则别无选择,只能通过编程方式添加行(因为您要么没有足够的行,要么会有多余的行)。如果你总是有一个固定的数量(即“每页5个结果”),那么用XML定义它们就是find,你可以制作额外的,而不是用作
android:visibility=“gone”
。#2不,只需在它前面的同一行中设置一个文本和一个列表。就像一个记分卡或一个内容表一样
<LinearLayout>
    <LinearLayout>
        <ListView>
        <TextView>