android – CollapsingToolbarLayout ImageView不可滚动

前端之家收集整理的这篇文章主要介绍了android – CollapsingToolbarLayout ImageView不可滚动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用 cheesesquare – android support library example是否可以使Header ImageView可滚动?
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

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

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll" 
            app:layout_collapseMode="parallax" />
            ...
    </android.support.design.widget.CollapsingToolbarLayout>

<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">
    ....

请注意,我已经添加添加android:fillViewport =“true”到NestedScrollView并添加了app:layout_scrollFlags =“scroll”to
ImageView但是当试图从ImageView滚动时没有任何反应.

解决方法

好的,我在错误报告中做了一些研究,这是设计支持库中的一个已知错误.

Check out the bug report here

摘抄

I have taken a look at the implementation that backs CoordinatorLayout/AppBarLayout/the Behavior classes etc. The AppBarLayout uses the behavIoUr defined in AppBarLayout.Behavior by default. This extends ViewOffsetBehavior which in turn extends Behavior. The base Behavior class has the methods onInterceptTouchEvent() and onTouchEvent(),both of which return false (meaning “we don’t want to handle touch events”). These methods are not overridden by either ViewOffsetBehavior or AppBarLayout.Behavior,meaning that the touch is left unhandled – which is why it does nothing.

A possible workaround for third-party developers would be to extend AppBarLayout.Behavior and implement onInterceptTouchEvent() and onTouchEvent() and manipulate the app bar accordingly.

影片

这些显示了当前和预期的行为.这些也来自错误报告.

> https://youtu.be/xWadOVEaTSY
> https://youtu.be/J8ITp6RusZo

原文链接:https://www.f2er.com/android/315383.html

猜你在找的Android相关文章