0

我试图建立和应用,显示组织的数据,所以我想,基本上是TableLayout将是一个不错的主意,只为让他们在行,所以我不知道什么正确的如何做到这一点?我有这个在我的XMLAndroid的 - 列表视图内tableLayout

<?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。我怎样才能解决这个问题?有没有另一种方法来做到这一点easly?

回答

1

所以我不解的是,没有拿起tablelayout。我怎样才能解决这个问题?有没有另一种方法来做到这一点easly?

不太,渲染是TableLayout的考虑,但由于lint工具检测到你有两个意见时,你只需要一个(A LinearLayoutTableLayout),是警告你,应该删除其中的一种布局,因为它可以提高性能,同时不影响页面的功能。

我会加,你有一个单行一个TableLayout。 TableLayout旨在允许其内容根据其所有行对列进行格式化。随着单列TableLayout &行一起充当的LinearLayout:

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

由于您TableLayout没有在这种情况下添加任何另外的布局也变得过时,你会从删除它,改变获得资源提升LinearLayout的orientationhorizontal

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

+0

哇人,感谢信息,真正有启发性,我会做到这一点,看看出来,但其他的事情,如果我想添加更多的行后来说从信息在数据库中,最好以编程方式执行或将布局设置为xml文件? – DeX03 2012-02-10 15:17:26

+0

如果你拉出可变数量的行,你别无选择,只能以编程方式来做(因为你没有足够的,否则你会有多余的行)。如果你总是有一定数量(即,你有“每页5个结果”),那么用XML定义它们,你可以使额外的东西不被用作android:visibility =“gone”。 – Graeme 2012-02-10 15:20:31

0

1)它说:可能这样可以避免得出结论,相信你自己年轻的徒弟!但是,是的,父看起来对我没用太:)

2)使用Table布局之外的ListView不会改变行布局在列表中,如果这是你想要达到的目标。

您可能已经看到了这个,但Developers page offers a really good tutorial可以帮助您为您的ListView(此示例使用ListActivity)创建良好的基础。然后,您可以使用TableLayout ...等修改行的布局。

+0

#2不,它只是在同一行中直接在它前面设置文本和列表。只是为了使像记分卡或内容表有点布局 – DeX03 2012-02-10 16:51:10

1

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

此的LinearLayout布局或其RelativeLayout的父母也没用

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