【问题标题】:Unable to scroll collapsing toolbar with recyclerview using fragment无法使用片段滚动带有 recyclerview 的折叠工具栏
【发布时间】:2020-01-05 14:35:57
【问题描述】:

我在单个活动中都使用 NavigationView 和 BottomMenu。在单击底部菜单时使用片段我正在使用折叠工具栏和 Recyclerview。当我滚动 recyclerview 时,只有 recyclerview 滚动但折叠工具栏没有折叠。这是我的代码。请帮帮我。

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F1F1F1"
android:focusable="true"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:fitsSystemWindows="true"
    android:background="@android:color/transparent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways|snap">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:layout_collapseMode="parallax">

            <androidx.viewpager.widget.ViewPager
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:id="@+id/vp_new_banner"/>

            <com.viewpagerindicator.CirclePageIndicator
                android:id="@+id/vp_indicator"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_marginTop="150dp"
                android:elevation="8dp"
                android:paddingTop="12dp"
                app:centered="true"
                app:fillColor="@color/colorPrimaryDark"
                app:pageColor="#ffffff"
                app:snap="false" />

        </RelativeLayout>

    </com.google.android.material.appbar.CollapsingToolbarLayout>

</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/new_data_2" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

    标签: android android-recyclerview android-collapsingtoolbarlayout


    【解决方案1】:

    你能发布 RecyclerView 所在位置的 xml 代码吗?我的猜测是你没有为 RecyclerView 包含app:layout_behavior="@string/appbar_scrolling_view_behavior"

    【讨论】:

    • 我可以共享 xml 代码,但我想在这里明确一下,我已经将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 用于 RecyclerView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 2017-01-10
    • 1970-01-01
    • 2015-09-26
    • 2023-03-15
    • 2016-03-09
    相关资源
    最近更新 更多