Android:如何避免RecyclerView物件上的涟漪跳动

时间:2019-02-06 17:20:38

标签: android android-recyclerview android-constraintlayout

我有一个ConstraintsLayout,它在扩展RecyclerView.Adapter<RecyclerView.ViewHolder>的适配器中被放大。 我将onLongClickListener设置为开始波纹效果。我正在使用简单的here找到的RippleBackground库。

我的问题是,长按开始后,波纹开始起作用,但是几秒钟后,它会跳到recyclerView中的其他项目,或者在我想要它之前消失(当我结束长按时)。< / p>

当“回收者”视图只有1个项目时,它可以正常工作。但否则会破坏并执行上述行为。

我尝试在适配器的ItemViewHolder中调用itemView.stopNestedScroll,但这似乎不起作用。

下面是我要设置的听众。

private View.OnClickListener onClickListener = ignored ->
        listener.onRowClicked(getAdapterPosition());

private View.OnLongClickListener onLongClickListener = ignored -> {
        rippleBackground.startRippleAnimation();
        itemView.getParent().requestDisallowInterceptTouchEvent(true);
        return true;
    };

//Listener just to check if finger is lifted after longPress
//since user should be able to move finger anywhere on screen and not cancel ripple until finger is lifted.
private View.OnTouchListener onTouchListener = (view, motionEvent) -> {
   if (rippleBackground.isRippleAnimationRunning() && motionEvent.getAction() == MotionEvent.ACTION_UP) {
          rippleBackground.stopRippleAnimation();
        }
          return false;
    };

理想情况下,一旦用户在RecyclerView中长按某个项目,该项目应开始起波纹,并且用户可以自由移动手指,即使在特定项目的观察者之外,也只有在抬起手指后波纹才会停止。

0 个答案:

没有答案