Android - tableLayout 内的 ListView

发布于 2025-01-04 04:35:46 字数 1383 浏览 0 评论 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"

所以我的理解是,没有拾取 表格布局。我该如何解决这个问题?还有另一种方法可以轻松做到这一点吗?

I'm trying to build and app that shows organized data so I'm thinking that basically a TableLayout would be a good idea, just to keep them in rows, so I'm wondering whats the correct way to do it? I have this in my 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>

then it's just that the TableLayout tag and TableRow tag displays a warning that says:

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

so what I understand is that is not picking up the TableLayout. how can I fix this? is there another way to do this easly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜唯美灬不弃 2025-01-11 04:35:46

所以我的理解是,没有选择表格布局。我该如何解决这个问题?还有其他方法可以轻松做到这一点吗?

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

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

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

由于您的 TableLayout 没有添加任何附加布局,在这种情况下它就变得过时了,您将通过删除它并将 LinearLayout 的 orientation 更改为 水平

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

so what i understand is that is not picking up the tablelayout. how can i fix this? is there another way to do this easly?

Not quite, the renderer is taking account of the TableLayout but because the lint tool has detected that you have two views when you only need one (A LinearLayout and TableLayout) it is warning you that you should remove one of these layouts as it will boost performance while not effecting the functionality of the page.

I will add, you have a TableLayout with just a single row. TableLayout's are designed to allow their contents to format their columns based upon all of their rows. With a single Row the TableLayout & Row together are acting as a LinearLayout:

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

Since your TableLayout isn't adding any addition layout in that case it becomes obsolete and you will gain a resource boost from removing it and changing the orientation of LinearLayout to horizontal.

If you're planning to add more TableRow's later, then you should instead remove the LinearLayout for the same reason - it will then become the view which is not adding extra information: your table layout will be entirely responsible for the layout so you might as well make it the parent of the layout file (remember to add xmlns:android="http://schemas.android.com/apk/res/android" attribute to it if you do.)

韵柒 2025-01-11 04:35:46

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

这个LinearLayout布局或其RelativeLayout父级没有用

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

In general I've seen the stronger warning:

This LinearLayout layout or its RelativeLayout parent is useless

when this is not the case. For example, this can happen if I've nested a linear layout inside a relative layout. The relative layout positions the linear layout exactly where I want it, the linear layout takes up space. Both are non-useless uses to me.

邮友 2025-01-11 04:35:46

1)它说可能,所以不要下结论,相信自己,年轻的学徒!但是,是的,父级对我来说也没什么用:)

2) 在 ListView外部使用表布局不会改变列表中的行布局,以防万一你想要实现的目标。

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

1) it says possibly so avoid drawing conclusions, trust yourself young padawan! But yes, the parent looks useless to me too :)

2) Using Table layout outside of your ListView wont change the rows' layout in the list, in case this is what you want to achieve.

You might have seen this but the Developers page offers a really good tutorial that can help you create a good base for your ListView (this example uses a ListActivity). Then on you can modify the rows' layouts using TableLayout ...etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文