【问题标题】:How to fix ListView inside ScrollView?如何修复 ScrollView 中的 ListView?
【发布时间】:2020-02-21 08:42:49
【问题描述】:

我需要在 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>

【问题讨论】:

标签: android xml layout interface


【解决方案1】:

将您的 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>

【讨论】:

  • 我必须将android:fillViewport="true" 放在AndroidManifest 中的哪个位置?
  • 在 ScrollView 标签中 我也编辑了我的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-19
  • 2016-08-31
  • 1970-01-01
  • 1970-01-01
  • 2011-06-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多