使用nestedscrolllayout的Appbarlayout滚动行为

时间:2018-05-06 17:49:09

标签: android android-recyclerview android-appbarlayout android-nestedscrollview

所以我对 NestedScrollLayout AppbarLayout 有这个奇怪的问题。我的 NestedScrollLayout 有三个 recyclerviews ,可以水平滚动, AppbarLayout 有工具栏,当垂直滚动时,所有工作正常,除非我开始水平滚动 recyclerview 并且不释放我的手指我开始垂直滚动 AppbarLayout 不会崩溃,但 NestedScrollLayout 滚动。

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar”
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize">
    </android.support.v7.widget.Toolbar>

    <RelativeLayout
        android:id="@+id/toolbar_small”
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent">
    </RelativeLayout>

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.CardView
            android:id="@+id/child”
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll">
        </android.support.v7.widget.CardView>

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

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior”>

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/label_a”
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text=“label a”
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <RelativeLayout
                    android:id="@+id/recycler1_holder”
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/label_journal">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler1”
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"
                         app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/label_journal" />
                </RelativeLayout>


                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/recycler1_holder" />


                <RelativeLayout
                    android:id="@+id/recycler2_holder”
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView4">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler2”
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

                </RelativeLayout>


                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/recycler2_holder" />

                <RelativeLayout
                    android:id="@+id/recycler3_holder”
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView5">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler3”
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

                </RelativeLayout>


                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/recycler3_holder" />

                <RelativeLayout
                    android:id="@+id/recycler4_holder”
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView6">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler4”
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

                </RelativeLayout>
            </android.support.constraint.ConstraintLayout>
        </android.support.v4.widget.NestedScrollView>
    </android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>

0 个答案:

没有答案