我有一個佈局: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
你似乎使用'match_parent'作爲你的'ListView'的高度...... –
如果我使用match_parent或wrap_content作爲我的ListView或TableRow的高度,沒有什麼變化。我只能手動設置高度。 – adamsc
@adamsc看看這裏,http://blog.lovelyhq.com/setting-listview-height-depending-on-the-items/ –