2016-10-22 94 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

人們已經做到了,你可以照原樣使用它。 –