【发布时间】:2013-01-07 10:23:52
【问题描述】:
我正在动态创建一些TextView、ImageView、HtmlView 并将其添加到以下布局中。
<?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?
【问题讨论】:
-
尝试我发布的解决方案。
标签: android android-layout android-listview android-linearlayout