gpt4 book ai didi

android - 如何点击 recyclerview?

转载 作者:太空狗 更新时间:2023-10-29 15:50:30 25 4
gpt4 key购买 nike

首先,我在这个问题上苦苦挣扎了很长时间。我不知道如何解决问题,所以我遵循了这些步骤和教程,但没有成功。

  1. Click through recycler view empty space
  2. Click through a recyclerview list item

还有一堆关于 StackOverflow 的问题。我也写了自己的代码。可能是我在做一些愚蠢的事情,但我无法弄清楚。

mRecyclerView.setOnTouchListener((v, event) -> {
RectF rectf = new RectF((int) event.getX(),
(int) event.getY(),
0, 0);
boolean contains = getCenter(mHeaderPopUp).contains(rectf);
if (contains) {
Toast.makeText(mContext, "Clicked", Toast.LENGTH_SHORT).show();
}
return false;
});

private RectF getCenter(View view) {
Rect rect = new Rect();
view.getLocalVisibleRect(rect);
RectF dimens = new RectF((rect.left + rect.width() / 2),
(int) (rect.top + rect.height() / 2),
0, 0);
return dimens;
}

所以现在我已经尝试了所有这些方法,但是我无法通过 recyclerview 单击到 recyclerview 下面的 View ,您可以在下图中看到。 recyclerview 覆盖屏幕上的所有 View ,我需要将点击传递到下面的 recyclerview 我不想将这些 View 放在 recyclerview 上方,因为当您滚动 recyclerview 时它将被动画化并覆盖所有 View 及其项目。提前致谢。 This is the image

最佳答案

我想我找到了。

使用recycler.setLayoutFrozen(true);

您仍然可以将 onClickListeners 分配给您的项目,但如果您不这样做,点击将会通过。

来自RecyclerView.java的源码:

@Override
public boolean onTouchEvent(MotionEvent e) {
if (mLayoutFrozen || mIgnoreMotionEventTillDown) {
return false; // <= This will prevent the RecyclerView from getting the MotionEvent
}
...
}

https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java#2795

关于android - 如何点击 recyclerview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45116198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com