Android 4.x上ScrollView中的RecyclerView,RecyclerView无法滚动

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

[我在RecyclerView中放了ScrollView,将RecyclerView设置为明确的高度,当我在android 5.0上运行时,可以,RecyclerView可以滚动,但是在4.x上,只有外部[ C0]滚动。

我发现5.0 sdk更新了ScrollView源代码以支持嵌套滚动,我想找出使用​​4.x中新功能的方法。

所以我试图将ScrollView更改为ScrollView,但仍然无法正常工作。 5.0和4.x有相同的问题:android.support.v4.widget.NestedScrollView可以滚动,但是当触摸RecycleView时,除非我拖动视图而没有单击事件,否则外部RecyclerView不能再滚动。触摸具有点击事件的视图,NestedScrollView不会滚动。

然后我尝试将NestedScrollView更新为最新版本

support.v4

仍然使用compile 'com.android.support:support-v4:23.1.1'代替android.support.v4.widget.NestedScrollView,现在它在5.0上可以正常使用,但是4.x仍然与早期support.v4版本存在相同的问题。

这是我的代码。整个NestedScrollView外面,顶部有一些布局或片段,底部有片段的ViewPager,RecyclerView在ViewPager的片段中。该代码在5.0和4.x之间具有不同的运行行为。

ScrollView
android android-recyclerview android-scrollview
1个回答
0
投票

问题已解决。我将sdk更新为较新的版本,一切正常。

将编译SDK版本和构建工具版本设置为:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="hz.rrs.shop.ShopIndexActivity">

    <hz.rrs.common.views.TitleView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/asi_sc"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/title">

        <LinearLayout
            android:id="@+id/asi_ll_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <fragment
                android:id="@+id/fragment4"
                android:name="hz.rrs.shop.ShopHeaderFragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:layout="@layout/fragment_shop_header" />

            <ImageView
                android:id="@+id/asi_iv_service"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:adjustViewBounds="true"
                android:onClick="onClick"
                android:scaleType="fitCenter"
                android:src="@mipmap/shopindex_img_service" />

            <fragment
                android:id="@+id/fragment2"
                android:name="hz.rrs.shop.HeadlineFragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:layout="@layout/fragment_headline" />

            <fragment
                android:id="@+id/fragment3"
                android:name="hz.rrs.shop.PuzzleFragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                tools:layout="@layout/fragment_puzzle" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/asi_ll_drag"
                android:layout_marginTop="8dp">
                <android.support.design.widget.TabLayout
                    android:id="@+id/tabLayout"
                    style="@style/CustomTablayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewPager"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>

        </LinearLayout>

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

    <ImageButton
        android:id="@+id/asi_ibtn_contact"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="200dp"
        android:background="@null"
        android:onClick="onClick"
        android:src="@mipmap/shopindex_btn_contact"
        android:layout_alignParentRight="true" />

</RelativeLayout>

将目标SDK版本设置为

compileSdkVersion 23
buildToolsVersion '23.0.2'

也将support.v4更新到23

targetSdkVersion 23

然后,RecyclerView可以在5.0和4.x的v4.NestedScrollView中嵌套滚动。

所以可能是5.x SDK的错误。

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