如何修复ScrollView中的ListView



我需要在ScrollBar中放入一个ListView。我知道这个主题还有其他问题,但答案非常复杂和糟糕。

ListView不显示它的所有元素,只显示第一个元素。

我的相关代码的主要结构:

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
....MORE ELEMENTS....
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
></ListView>
</LinearLayout>
</ScrollView>
</RelativeLayout>

ListView放在单独的LinearLayout父级中,或者根据您的选择将其添加到单独的.xml文件中并添加

android:fillViewport="true"

在你的滚动视图中,像这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!....MORE ELEMENTS....>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

最新更新