在下面的视图中滑动RecyclerView,未检测到点击 [英] RecyclerView Swipe with a view below not detecting click
问题描述
我有这样的RecyclerView
行布局
<Layout>
<BackgroundView>
<ForegroundView>
</Layout>
我正在使用ItemTouchHelper
来处理前景视图上的滑动(部分),如
I am using ItemTouchHelper
to handle swipes (partial) on the foreground view like
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
adapter.onItemSwiped(viewHolder);
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
View foregroundView = ((myViewHolder)viewHolder).getForegroundView();
getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX, dY, actionState, isCurrentlyActive);
//getSwipeLimit() used below returns the width of the delete icon
float translationX = Math.min(-dX, ((myViewHolder) viewHolder).getSwipeLimit());
foregroundView.setTranslationX(-translationX);
}
我已经在我的适配器类的BindViewHolder
中为backgroundview设置了一个单击侦听器.
I have set a click listener for the backgroundview in the BindViewHolder
of my adapter class.
@Override
public void onBindViewHolder(WhiteListViewHolder holder, Cursor cursor) {
//get name and number from the cursor here
holder.name.setText(name);
holder.number.setText(number);
holder.deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("whitelist", "yes clicked");
}
});
}
问题是,当背景视图未滑动时,背景视图接受点击,但是当视图被滑出后,背景视图停止接受点击.
The problem is, the background view is accepting clicks when the view is not swiped but after the view is swiped out, the background view stops accepting clicks.
请参考上图,如果我单击删除"按钮,则有时会恢复滑动视图,并且无法捕获点击.
Referring the above image, if I click on the delete button, the swiped view is recovered sometimes and it doesn't captures the click.
如果我让整个视图滑出,则单击左侧的空白区域也会带回滑动的视图.
If I let the whole view swipe out, clicking the empty space left also brings back the swiped view.
谢谢.
推荐答案
我解决了任务的第一部分-现在没有滑动就无法检测到. 但是在滑动后,点击无法检测到.
I resolved the first part of the task - now did not detect without swipe. But the click do not detect after swipe...
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if(actionState == ItemTouchHelper.ACTION_STATE_SWIPE){
if (dX < 0) {
backgroundView.setVisibility(View.VISIBLE);
}
else {
backgroundView.setVisibility(View.GONE);
}
}
}
这篇关于在下面的视图中滑动RecyclerView,未检测到点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!