我正在創建一些TextView
,ImageView
,HtmlView
動態並將其添加到以下佈局中。Android列表包裝內容
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ad_space"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="@drawable/navigation_bar"
android:visibility="gone" >
</LinearLayout>
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ScrollView
android:id="@+id/quiz_scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/quizView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/answer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
<ScrollView
android:id="@+id/quiz_scroll_viewTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/quizViewTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/answer_layoutTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
</ViewFlipper>
</LinearLayout>
在QuizView
我加入了在運行時的一些問題有關的意見,答案我創建一個列表視圖運行時間,並增加answer_layout
。我正在使用BaseAdapter
根據情況創建ListView
運行時。
但我的ListView
未顯示所有內容,它只顯示第一個單元格。
我已添加ListView
這樣。
ListView ansList = new ListView(Test.this);
ansList.setAdapter(adapter);
ansList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
ansCellLayout.addView(ansList);
它只顯示一個列表單元格。
如果我設置了一些int
值的高度,那麼它的顯示所有列表包含。
ansList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 600));
但我不能硬編碼列表視圖高度,因爲我的內容是動態的。
如何在此場景中將列表視圖設置爲WRAP_CONTENT
?
試試我發佈的解決方案。 –