【问题标题】:Nestedscrollview doesn't scroll child recyclerviewNestedscrollview 不滚动子 recyclerview
【发布时间】:2018-04-01 11:15:10
【问题描述】:

我遇到了这个问题,我在nestedscrollview 中有一个recyclerview,但是nestedscrollview 不滚动recyclerview。

这里是情况的 GIF:

recyclerview 显然有更多的孩子,但nestedscrollview 不会滚动到他们。

这是framents布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/bright_red"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/white"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            >

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/login_bg"
                app:layout_collapseMode="parallax" />


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:gravity="top"
                app:layout_collapseMode="pin"
                app:layout_collapseParallaxMultiplier="1.0"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:title="@string/fragment_future_title"
                />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:clipToPadding="false"
            android:paddingBottom="70dp"
            />

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

【问题讨论】:

  • 将此添加到您的回收站视图 xml android:nestedScrollingEnabled="true"
  • @udit7395 是的,我之前以编程方式禁用了它,这修复了它。它还导致/暴露了一个不同的问题,即投掷动作并非一直有效。它只是在飞行中停止。但将此作为答案发布,我会接受它
  • 两件事。首先,如果可能的话,您的卡片看起来很棒,请分享 xml(只是卡片)。其次,您可以尝试一下。您尝试过使用 ScrollView 吗?因此,如果您打算使用 Scrollview,那么在您的代码中只需编程禁用 recyclerView.setNestedScrollingEnabled(false);看看你得到的输出是否符合要求
  • Nestedscrollview 需要折叠工具栏布局才能工作。并且设置 nestedscrolling=false 是导致滚动不起作用的原始状态。你可以在github.com/KonstaL/Bullet-your-life查看代码。相关的布局代码可以在 daycard.xml 中找到
  • 没关系。显然我错了,并且 collapsingtoolbarlayout 不需要nestedscrollview 才能正常工作。删除 nestedscrollview 修复了投掷问题。谢谢审计!

标签: android android-layout android-recyclerview android-nestedscrollview


【解决方案1】:

将此添加到您的回收站视图 xml

android:nestedScrollingEnabled="true"

或者同样可以通过编程方式完成

recyclerView.setNestedScrollingEnabled(true);

【讨论】:

    猜你喜欢
    • 2020-06-01
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多