【发布时间】:2014-03-08 10:14:49
【问题描述】:
我在一项活动中有ListView 和ScrollView。现在,问题是ListView 和ScollView 不能一起工作。我有很多活动控件,所以我需要使用 ListView。
如果存在 ScrollView,则 ListView 的高度会降低,如图所示。
请帮助我防止这个问题。
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp" >
<TextView
android:id="@+id/tvRQPoint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="@color/green"
android:textSize="32sp" />
<TextView
android:id="@+id/tvRQQText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/questiontext"
android:textColor="@color/blue"
android:textSize="16sp" />
<TextView
android:id="@+id/tvRQQuestion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp" />
<ImageView
android:id="@+id/imgRQImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:contentDescription="@string/imgdesc" />
<ListView
android:id="@+id/lvRQOptions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:divider="#b5b5b5"
android:dividerHeight="1dp" />
<TextView
android:id="@+id/tvRQAnswer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btnRQNext"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="@string/next" >
</Button>
<Button
android:id="@+id/btnRQEndTest"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="@drawable/blue_bg"
android:text="@string/endtest"
android:textColor="@color/white" >
</Button>
</LinearLayout>
</ScrollView>
【问题讨论】:
-
@BlackTiger,谢谢。让我试试看。
-
@BlackTiger,它工作正常。但现在的问题是,当任何项目包含 2 行或更多行的内容时,它会隐藏列表视图的某些部分。如何预防这个问题?
-
在提供的链接中查看第一个答案并尝试设置此
ListView list = (ListView) view.findViewById(R.id.ls); setListViewHeightBasedOnChildren(list); -
我说这个答案工作正常。问题是,如果列表视图的任何项目的内容超过 2 行,那么它隐藏了列表视图的某些部分。
标签: android listview android-listview scrollview