当前位置: 首页 > 知识库问答 >
问题:

折叠工具栏和nestedscrollview无法平滑滚动

袁建木
2023-03-14

嵌套滚动视图在向下滚动时滚动流畅,但在向上滚动时滚动缓慢。向上滚动时折叠工具栏(带有图像视图和框架布局)不会呈现其内容(保持空白)。我已经尝试了折叠工具栏中的每个标志。

<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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">


<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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="wrap_content"
        android:fitsSystemWindows="true"

        app:contentScrim="?attr/colorPrimary"

        app:layout_scrollFlags="scroll|exitUntilCollapsed">


        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="100dp"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/pic"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.5"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/>

        <include
            android:id="@+id/framelayout"
            layout="@layout/header_layout"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            android:minHeight="100dp"/>


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


<!-- Your Scrollable View -->
<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"

    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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



      </LinearLayout>



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


<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#da1b75"
    android:orientation="horizontal"
    android:textColor="#ffffff"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_anchor="@id/appbar"
    app:layout_collapseMode="pin"
    app:title="">



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

共有3个答案

姜景焕
2023-03-14

我想你忘记了协调员布局的结束标签。另外,将工具栏放在折叠工具栏布局上

<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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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="wrap_content"
            android:fitsSystemWindows="true"

            app:contentScrim="?attr/colorPrimary"

            app:layout_scrollFlags="scroll|exitUntilCollapsed">


            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="100dp"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/pic"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.5"
                app:layout_scrollFlags="scroll|exitUntilCollapsed" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="#da1b75"
                android:orientation="horizontal"
                android:textColor="#ffffff"
                android:theme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_anchor="@id/appbar"
                app:layout_collapseMode="pin"
                app:title="Your title">

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


<!-- What is this for?

            <include
                android:id="@+id/framelayout"
                layout="@layout/header_layout"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
                android:minHeight="100dp"/>
-->

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


    <!-- Your Scrollable View -->
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nested"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"

        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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



          </LinearLayout>



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

</android.support.design.widget.CoordinatorLayout>
卫骏
2023-03-14

更新:您可以通过右键单击ANDROID工作室中的图像并将图像转换为webp来减小图像大小。这将大大减小图像大小

非常简单。我挣扎了很久,最终知道这是我放在ImageView的src中的高分辨率图像的问题。解决方案:降低图像的分辨率,保持尺寸不变。(大概是用Photoshop)。

为我工作

冯嘉荣
2023-03-14

使嵌套滚动视图的直接子元素可点击(如果您只有一个子元素,请添加布局并将所有UI元素放入其中并使布局可点击)
android: clickable="true"
我面临类似的问题,这对我有用!

这是我一直在处理的代码 -

<?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"
tools:context="test.testrecycler.MaterialActivity"
>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:theme="@style/AppTheme.AppBarOverlay"
    android:fitsSystemWindows="true"
    >
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:expandedTitleTextAppearance="@style/expandedappbar"
        app:collapsedTitleTextAppearance="@style/collapsedappbar"
        app:statusBarScrim="@color/colorPrimaryDark"
        >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/sample"
            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" />

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

<include layout="@layout/content_material" />

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

这是包含NestedScrollView的content_material.xml文件。它有一个可点击的子元素(TextView)。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:id="@+id/content_material"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="test.testrecycler.MaterialActivity"
tools:showIn="@layout/activity_material">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:text="This is an association football club formed in 1983, based in the town of Dover, Kent, England. In the 1989–90 season Dover
    Athletic won the Southern League championship, but failed to gain promotion to the Football Conference as the club's ground did not meet
    the required standard. Three seasons later the team won the title again and this time gained promotion to the Conference, where they spent
    nine seasons before being relegated. The club was transferred to the Isthmian League Premier Division in 2004, but another poor season led
    the club to a further relegation. After three seasons in the Isthmian League Division One South, the club won the championship and promotion
    back to the Premier Division, and the following season won another championship and promotion to Conference South. In the 2013–14 season,
    Dover defeated Ebbsfleet United to return to the Conference Premier after a twelve-year absence. Nicknamed the Whites for their white shirts,
    they have played at the Crabble Athletic Ground since the club's formation. Their best performance in the FA Cup was reaching the third
    round proper in both the 2010–11 and 2014–15 seasons. (Full article...)
    Recently featured: Kalki Koechlin Rogue River (Oregon) Operation Ironside
    Archive By email More featured articles...
    his time gained promotion to the Conference, where they spent
    nine seasons before being relegated. The club was transferred to the Isthmian League Premier Division in 2004, but another poor season led
    the club to a further relegation. After three seasons in the Isthmian League Division One South, the club won the championship and promotion
    back to the Premier Division, and the following season won another championship and promotion to Conference South. In the 2013–14 season,
    Dover defeated Ebbsfleet United to return to the Conference Premier after a twelve-year absence. Nicknamed the Whites for their white shirts,
    they have played at the Crabble Athletic Ground since the club's formation. Their best performance in the FA Cup was reaching the third
    round proper in both the 2010–11 and 2014–15 seasons. (Full article...)" />
</android.support.v4.widget.NestedScrollView>
 类似资料:
  • 我正在开发一个Android应用程序,其中我使用、和来使用折叠工具栏功能。 我在布局中使用在相同的布局中展开和折叠。当我试图从屏幕中心向上滚动时,它不起作用,但当我试图从屏幕右角向上滚动屏幕时,它会平滑滚动。 下面提到的是我的 xml 文件 layout.xml 理想的结果是,当我尝试从屏幕中心向上滚动时,它应该像我从手机右角向上滚动一样工作。 请观看下面提到的视频,以便更清楚地了解问题 http

  • 我有一个带有,我想让它顺利工作。 我的问题是,当从内容向上滚动时,我的折叠工具栏不会自动展开,但当它到达顶部时会被阻止。然后我需要再次向上滚动以展开工具栏。 我想实现从内容平滑向上滚动,这将自动扩展我的< code > CollapsingToolbarLayout 这是我的代码: 我发现了一些类似的问题,但没有一个答案对我有用。

  • 我正在尝试在我的android应用程序中实现折叠工具栏。我可以按我希望的方式显示工具栏,但滚动时它不会塌陷。 我正在使用以下代码 activity.xml main_toolbar.xml 下面是屏幕的外观

  • 当我做快速挺举时,我有一个CollapsingToolbarLayout的问题。隐藏appBar也会发生同样的事情 我需要工具栏隐藏在滚动和折叠工具栏折叠。当滚动不是很快时,它工作得很好。 但是当它很快的时候——似乎appBar在那之后就崩溃并扩展了。但它没有扩展回来。 请看视频。 折叠工具栏布局 应用程序栏 似乎这个答案是我需要的,但它不起作用。 我的折叠工具栏布局的 xml :

  • 问题内容: 我有一个这样布置的应用程序,mainactivity包含2个带有相应片段的选项卡,第一个片段具有可正常使用的回收站视图,我试图在人向上或向下滚动时添加视差效果,不是确保我是否应该将其添加到片段的xml或mainactivity的xml中,我将其添加到mainactivity的xml并将片段包含为我的recyclerview,不用说视差不起作用,现在应用程序无法打开,我立即获取NullP

  • 有什么方法可以让Android设计支持库的折叠动画在滚动时更流畅?当我释放滚动时,它突然停止。但我想要的是:即使停止滚动,塌陷动画也会顺利继续。Android-ObservableScrollView和Scrollable是正在平滑崩溃的库。