Android Layout Shake(AppBarLayout和RecyclerView)

时间:2018-02-06 09:23:51

标签: android android-recyclerview android-coordinatorlayout android-appbarlayout

当我在AppBarLayout中使用大量内容RecyclerViewCoordinatorLayout时,有两个问题:

  1. 如果您的手指快速扫过AppBarLayout,则布局无法顺利滚动到RecyclerViewAppBarLayout将会反弹。

    < / LI>
  2. 如果您的手指向上扫过AppBarLayout,然后向下扫描RecyclerView,布局将会震动,因为AppBarLayout在第一次扫掠动作时有惯性。

  3. 如何在不更改布局结构的情况下解决此问题,或者如何在Behavior定义AppBarLayout来解决此问题?因为我可以通过没有AppBarLayout的布局来解决它,但这不是我想要的。

    My Project Address

    THX!

    <?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:orientation="vertical">
    
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:elevation="0dp">
    
            <TextView
                android:id="@+id/diary_cp_check_in_time"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:gravity="center"
                android:text="I'm AppBarLayout"
                android:textSize="36sp"
                app:layout_scrollFlags="scroll"/>
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/diary_info_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layoutManager="android.support.v7.widget.LinearLayoutManager"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </android.support.design.widget.CoordinatorLayout>
    

1 个答案:

答案 0 :(得分:0)

recyclerView.setNestedScrollingEnabled(false)在您的代码中使用此...当您设置recyclerView appBarScrollingBehavior的行为时,recyclerView将以嵌套方式滚动。将nestedScrollingEnabled设置为false将允许您自由滚动recyclerView ..并且您也不会获得shaky效果(向上和向下)..