Android - tableLayout 内的 ListView
我正在尝试构建显示组织数据的应用程序,所以我认为基本上 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不完全是,渲染器正在考虑 TableLayout,但因为
lint
工具检测到您在只需要一个视图时有两个视图(ALinearLayout
code> 和TableLayout
),它警告您您应该删除其中一种布局,因为它将提高性能,同时不会影响页面的功能。我要补充一点,你有一个只有一行的 TableLayout。 TableLayout 的设计允许其内容根据所有行来格式化其列。使用单行 TableLayout & Row 一起充当 LinearLayout:
由于您的 TableLayout 没有添加任何附加布局,在这种情况下它就变得过时了,您将通过删除它并将 LinearLayout 的
orientation
更改为水平
。如果您打算稍后添加更多
TableRow
,那么您应该出于同样的原因删除LinearLayout
- 然后它将成为不添加额外内容的视图信息:您的表格布局将完全负责布局,因此您不妨将其作为布局文件的父级(请记住添加xmlns:android="http://schemas.android.com/apk/res /android"
属性,如果你这样做的话。)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 (ALinearLayout
andTableLayout
) 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:
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 tohorizontal
.If you're planning to add more
TableRow
's later, then you should instead remove theLinearLayout
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 addxmlns:android="http://schemas.android.com/apk/res/android"
attribute to it if you do.)总的来说,我看到了更强烈的警告:
当情况并非如此时, 。例如,如果我将线性布局嵌套在相对布局中,则可能会发生这种情况。相对布局将线性布局精确定位在我想要的位置,线性布局占用空间。两者对我来说都是无用的用途。
In general I've seen the stronger warning:
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.
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 aListActivity
). Then on you can modify the rows' layouts usingTableLayout
...etc.