【问题标题】:CollapsingToolBarLayout and NestedScrollView smooth scroll issuesCollapsingToolBarLayout 和 NestedScrollView 平滑滚动问题
【发布时间】:2018-02-01 07:57:51
【问题描述】:

我将 CoordinatorLayout 与 CollapsingToolBar 和 NestedScrollView 一起使用。正在通过 RecyclerView 插入元素。每当我尝试向上或向下滚动时,滚动都不流畅,无论手势的速度如何,它都很慢。我尝试了here 的解决方案,但它并没有解决我的问题。 所以我不知道是什么导致了这个问题或如何解决它。

这是我的 xml 布局

<?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:id="@+id/main_screen_frame">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="225dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|enterAlways"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/toolbarImage"
                android:layout_width="150dp"
                android:layout_height="100dp"
                android:scaleType="centerCrop"
                android:src="@drawable/logo"
                android:layout_gravity="center"
                app:layout_scrollFlags="scroll|enterAlways"
                app:layout_collapseMode="parallax"/>

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <android.support.v7.widget.SearchView
                        android:id="@+id/search_view_id"
                        android:layoutDirection="rtl"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:queryHint="@string/search_view_hint"
                        android:queryBackground="@color/colorWhite"
                        android:layout_gravity="right"/>

                </LinearLayout>

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

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <LinearLayout
                android:id="@+id/search_panel_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layoutDirection="rtl">

                <TextView
                    android:id="@+id/text_view_id"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:textAlignment="center"
                    android:text="@string/secondary_title"
                    android:layout_marginBottom="5dp"/>

            </LinearLayout>

            <FrameLayout
                android:id="@+id/fragment_layout_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/search_panel_id"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

            </FrameLayout>

        </RelativeLayout>

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

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

FrameLayout 是具有不同可滚动 RecyclerView 的不同片段的占位符。 提前致谢。

【问题讨论】:

    标签: android android-layout android-coordinatorlayout android-collapsingtoolbarlayout android-nestedscrollview


    【解决方案1】:

    布局结构似乎还可以。所以问题可能就在这里。 android:src="@drawable/logo".

    尝试将其移至drawable-nodpi 目录。 加载 Picasso / Glide 也会提高性能。

    【讨论】:

    • 感谢您的回复,但是将图像移动到另一个文件夹并没有解决问题。
    • 你试过毕加索吗?
    • 是的,不幸的是它没有帮助。
    【解决方案2】:

    使用this 解决方案解决了我的问题。问题是我正在使用 RecycleView,它来自 NestedScrollVoew 内部的注入片段。我猜它们都相互矛盾,导致滚动缓慢。

    【讨论】:

      【解决方案3】:

      recyclerViewsetNestedScrollingEnabled(false);

      以上行使NestedScrollView 中的recyclerview 滚动更流畅。

      【讨论】:

        猜你喜欢
        • 2017-03-11
        • 1970-01-01
        • 2016-07-31
        • 2016-03-19
        • 2016-11-02
        • 2015-08-28
        • 2016-12-18
        • 2016-02-04
        • 1970-01-01
        相关资源
        最近更新 更多