【问题标题】:How to scroll Recyclerview inside CollapsingToolbarLayout如何在 CollapsingToolbarLayout 内滚动 Recyclerview
【发布时间】:2016-09-05 12:41:46
【问题描述】:

我在 CollapsingToolbarLayout 中有 recyclerview,我希望它可以滚动,但事实并非如此。当我滚动时,appbar 正在滚动,但不是 recyclerview。我尝试了不同的东西,但它不起作用。这是我的代码:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/caves_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll"
            android:nestedScrollingEnabled="true"
            app:titleEnabled="false">

            <ImageView
                android:id="@+id/caves_backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:background="@mipmap/mount"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop" />



            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler"
                android:layout_width="match_parent"
                android:layout_height="200dp"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                app:theme="@style/WhiteToolbarStyle"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="none" />

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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nested"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/content"/>

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

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

【问题讨论】:

    标签: android android-recyclerview android-collapsingtoolbarlayout


    【解决方案1】:

    我找到了解决方案:

    recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
            @Override
            public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                int action = e.getAction();
                switch (action) {
                    case MotionEvent.ACTION_MOVE:
                        rv.getParent().requestDisallowInterceptTouchEvent(true);
                        break;
                }
                return false;
            }
    
            @Override
            public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    
            }
    
            @Override
            public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
    
            }
        });
    

    【讨论】:

    • 我面临同样的问题,但这个解决方案对我不起作用。你能帮我解决同样的问题吗?
    • 正如附加信息:此解决方案不适用于棒棒糖之前的设备
    【解决方案2】:

    在 Appbarlayout 中设置水平轨道为 false

    这解决了问题。如果它不起作用,请告诉我

    代码

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="#fff"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:toolbarId="@+id/toolbar2"
        android:scrollbarAlwaysDrawHorizontalTrack="false"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleTextAppearance="@style/TransparentText">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-13
      • 2016-07-31
      • 2017-06-09
      • 2023-03-03
      • 2019-03-11
      相关资源
      最近更新 更多