【发布时间】:2017-08-23 18:50:41
【问题描述】:
我有一个布局,其中 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>
回收器仅使用顶部填充或边距消耗所有点击。我需要点击才能通过,但滑动应该留在回收器中以进行滚动。
编辑:
我的点击工作正常,解决方案是:
recycler.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
background.dispatchTouchEvent(event);
return false;
}
});
现在我遇到了一个问题,因为我翻译了背景(视差),所以点击没有到达正确的位置。我也必须翻译事件吗?
【问题讨论】:
-
我已经以与您相同的方式解决了这个问题,但是似乎调度的触摸事件似乎并不总是有效。它的行为就好像有一个 0 的触摸斜率。您是否遇到过这种情况,或者有人知道解决方案吗?
标签: android android-recyclerview