【问题标题】:Appbarlayout scroll upward just when recyclerview scroll and not when user touch up the appbarlayout contentAppbarlayout 仅在 recyclerview 滚动时向上滚动,而不是在用户触摸 appbarlayout 内容时向上滚动
【发布时间】:2018-11-02 06:15:56
【问题描述】:

我有一个 AppBarLayout ,其中包含一个 FrameLayout ,其中包含一个 ImageView 。 FrameLayout 本身位于 CollapsingToolbarLayout 中。 在 AppBarLayout 的底部,有一个 RecyclerView。

代码如下

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             xmlns:app="http://schemas.android.com/apk/res-auto"
                                             android:id="@+id/root"
                                             android:layout_width="match_parent"
                                             android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:overScrollMode="ifContentScrolls">

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:layout_height="wrap_content">

        <FrameLayout
            android:id="@+id/img_video_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            >

            <ImageView
                android:id="@+id/cropper_view"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:background="#ff282828"
                android:visibility="visible"/>
        </FrameLayout>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/img_video_view"/>

当用户触摸 AppbarLayout 部分时,我不想滚动发生。我希望仅在用户触摸 recyclerview 时向上滚动。 我该怎么做?

提前致谢。

【问题讨论】:

    标签: android android-recyclerview material-design android-coordinatorlayout android-appbarlayout


    【解决方案1】:

    我解决了我的问题。 :-) 根据我的问题,我想将 AppBarLayout 的触摸事件传递给其中的 ImageView。我重写了 AppBarLayout、CollapsingToolbarLayout 和 FrameLayout 的 onInterceptTouchEvent 如下并返回 false;

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }
    

    这样,没有一个父视图捕捉到触摸事件,触摸事件将传递给ImageView。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 2015-09-27
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      相关资源
      最近更新 更多