与NestedScrollView,RecyclerView(水平)NestedScrolling,里面CoordinatorLayout里面、水平、RecyclerView、NestedScroll

2023-09-07 10:55:05 作者:别撑了你又不是伞

我有一个UI设计与CollapsingToolbarLayout,像下面。

I have a UI design with CollapsingToolbarLayout, like following.

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout

        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

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

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="24dp">

        <!-- Hiding unrelated code -->

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/card_margin"
            android:padding="16dp">


                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recycler_movie_suggestion"
                    android:layout_width="match_parent"
                    android:layout_height="170dp"
                    android:fillViewport="true"
                    android:nestedScrollingEnabled="false"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

    </LinearLayout>

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

我的问题是,滚动是好的只有当我触摸滚动外的RecyclerView的区域。如果我尝试RecyclerView内垂直滚动,滚动被困,只有NestedScrollView正在滚动时,CollaspingToolbarLayout不collasping。

My problem is, the scrolling is fine ONLY when I touch and scroll the area OUTSIDE the RecyclerView. If I try to scroll vertically inside the RecyclerView, the scrolling is "trapped" and ONLY the NestedScrollView is scrolling, the CollaspingToolbarLayout ISN'T collasping.

推荐答案

您需要禁用嵌套滚动编程。它似乎并不如用XML来正常工作。

You need to disable nested scrolling programatically. It doesn't seem to work correctly if done in xml.

recyclerView.setNestedScrollingEnabled(false);
 
精彩推荐
图片推荐