2016-10-22 53 views
-2

我有一个布局:ScrollView - > RelativeLayout - > TableLayout - > TableRow - > ListView。我不知道如何根据内容更改ListView的高度。我有一个适配器,但ListView的高度不会改变。它也不是可滚动的,但它不需要。我读过使用嵌套ListView是一种不好的做法,但我看不到任何解决方案,因为Column0中的图像源取决于多个变量(它不需要适配器)。我不能使用LinearLayout而不是ListView,因为我需要一个适配器。调整嵌套ListView的高度

例子:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/ScrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="${relativePackage}.${activityClass}" > 
<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="1000dp" 
     android:orientation="vertical" > 
<TableLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:divider="#000000" 
      android:showDividers="middle" > 

      <TableRow 
       android:id="@+id/tableRow1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <Button 
        android:id="@+id/button0" 
        android:layout_width="100sp" 
        android:layout_height="100sp" 
        android:layout_marginLeft="10sp" 
        android:layout_marginTop="10sp" /> 

       <ListView 
        android:id="@+id/listView0" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        > 

我想拥有什么: The conception

+0

你似乎使用'match_parent'作为你的'ListView'的高度...... –

+0

如果我使用match_parent或wrap_content作为我的ListView或TableRow的高度,没有什么变化。我只能手动设置高度。 – adamsc

+0

@adamsc看看这里,http://blog.lovelyhq.com/setting-listview-height-depending-on-the-items/ –

回答

0

理想的情况下,这样做是一个坏主意。

您可以编写一个自定义视图,扩展如LinearLayout,支持使用适配器填充视图。像这样:NestableListView

+0

所以实际上重写一个ListView ? –

+0

人们已经做到了,你可以照原样使用它。 –