点击RecyclerView空白区域

Dar*_*usL 6 android android-recyclerview

我有一个布局,其中RecyclerView位于具有几个按钮的另一个布局之上.第一个回收商项目是一个带有较大上边距的标题,以在其上方创建一个空白区域.现在我希望点击通过该开放空间工作,刷卡也应该滚动回收器.视图位于一个简单的框架中.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <package.FeedBackgroundView
        android:id="@+id/feed_background"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:scrollbars="vertical"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

回收者仅使用顶部填充或边距消耗所有点击.我需要点击才能通过,但是滑动应该留在回收器中进行滚动.

编辑:

我的点击工作,解决方案是:

recycler.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            background.dispatchTouchEvent(event);
            return false;
        }
    });
Run Code Online (Sandbox Code Playgroud)

现在我有一个问题,因为我翻译了背景(视差),点击没有到达正确的位置.我是否也要翻译这些活动?

Dar*_*usL 4

好吧,我解决了这两个问题。

recycler.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            MotionEvent e = MotionEvent.obtain(event);
            Matrix m = new Matrix();
            m.setTranslate(0f, -backgroundTranslation);
            e.transform(m);
            background.dispatchTouchEvent(e);
            e.recycle();
            return false;
        }
    });
Run Code Online (Sandbox Code Playgroud)

这会复制回收器触摸事件并“固定”其位置。背景的翻译是translationY。