Android - tableLayout 中的 ListViews [英] Android - ListViews inside tableLayout

查看:22
本文介绍了Android - tableLayout 中的 ListViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<表格布局android:id="@+id/tableLayout1"android:layout_width="fill_parent"android:layout_height="fill_parent"><表格行><文本视图android:layout_width="fill_parent"android:layout_height="fill_parent"android:text="@string/hello" ></TextView><列表视图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 标签显示一个警告说:

这个 TableLayout 布局或者它的 LinearLayout 父级可能没用"

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

解决方案

所以我的理解是这不是在选择表格布局.我怎样才能解决这个问题?有没有其他方法可以轻松做到这一点?

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

我要补充的是,您有一个只有一行的 TableLayout.TableLayout 旨在允许其内容根据其所有行设置其列的格式.使用单行 TableLayout &行一起充当 LinearLayout:

<线性布局><列表视图><文本视图>

由于您的 TableLayout 在这种情况下没有添加任何附加布局,因此它会过时,您将通过删除它并将 LinearLayout 的 orientation 更改为 horizo​​ntal 获得资源提升>.

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

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?

解决方案

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.)

这篇关于Android - tableLayout 中的 ListViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆