具有多个ListView的嵌套ScrollView无法滚动

问题描述 投票:0回答:1

我只希望嵌套的滚动视图滚动,我不希望列表滚动。由于某些原因,scrollview无法滚动。我调查了与嵌套滚动视图,滚动视图和列表视图相关的多篇文章,这些解决方案都无济于事。滚动视图无法正常工作很奇怪,我不确定是否丢失了某些内容。

这是我的代码:

<android.support.v4.widget.NestedScrollView
    android:id="@+id/ns_scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/grey"
        android:orientation="vertical">

        <TextView
            style="@style/customFontStyleBook"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:padding="5dp"
            android:text="Heading 1"
            android:textColor="#000"
            android:textStyle="bold"/>


        <ListView
            android:id="@+id/ll1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/grey"
        android:orientation="vertical">

        <TextView
            style="@style/customFontStyleBook"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:padding="5dp"
            android:text="Heading 2"
            android:textColor="#000"
            android:textStyle="bold"/>

        <ListView
            android:id="@+id/ll2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

            </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/grey"
        android:orientation="vertical">

        <TextView
            style="@style/customFontStyleBook"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:padding="5dp"
            android:text="Heading 3"
            android:textStyle="bold"
            android:textColor="#000" />

        <ListView
            android:id="@+id/ll3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

    </LinearLayout>
 </android.support.v4.widget.NestedScrollView>
android listview android-listview android-scrollview nestedscrollview
1个回答
0
投票

您应该在Scrollview中使用Nestedscrollview,在这里给您一个使用Nestedscrollview的示例:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="<a class="vglnk" href="http://schemas.android.com/apk/res/android" rel="nofollow" dideo-checked="true"><span>http</span><span>://</span><span>schemas</span><span>.</span><span>android</span><span>.</span><span>com</span><span>/</span><span>apk</span><span>/</span><span>res</span><span>/</span><span>android</span></a>"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:gravity="center"
        android:orientation="vertical">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:background="@android:color/white"
            android:padding="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/nested_scroll_text"/>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/guava"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/jackfruit"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/mix_fruit"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/pomegranate"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/strawberry"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/zespri_kiwi"/>

    </LinearLayout>

</ScrollView>

请参见此处以获取更多详细信息:https://tutorialwing.com/android-nestedscrollview-tutorial-example/

© www.soinside.com 2019 - 2024. All rights reserved.