简体   繁体   English

使用ItemTouchHelper与RecyclerView中的锁定ViewHolder进行交互

[英]Interaction with locked ViewHolder in RecyclerView using ItemTouchHelper

I'm using a custom ItemTouchListener to make my items in a RecyclerView swipeable. 我正在使用自定义的ItemTouchListener来使我的项目在RecyclerView滑动。 The ViewHolders have a RelativeLayout so when I'm swiping them left a pair of Buttons appear. ViewHolders具有RelativeLayout因此当我向它们滑动时,会出现一对Buttons But now my problem is that my Buttons are not clickable at the first touch after the swipe. 但是现在我的问题是,在滑动后的第一次触摸时,我的Buttons无法单击。 I need to click the ViewHolder 3 times so i can interact with it again (clicking buttons, edit textviews). 我需要单击ViewHolder 3次,这样我才能再次与其交互(单击按钮,编辑textviews)。

In my custom ItemTouchHelper onChildDraw method I'm doing something like this to keep the ViewHolder at a specific position and make the buttons under the swipeable view visible: 在我的自定义ItemTouchHelper onChildDraw方法中,我正在执行以下操作以将ViewHolder保持在特定位置,并使可滑动视图下的按钮可见:

if(dX > itemView.getWidth() / 4){
    dX = itemView.getWidth() / 4;
}
((CustomViewHolder) viewHolder).getSwipeAbleLayout().setTranslationX(dX);

It seems like the ViewHolder is still in swipe mode during the first two clicks. 在前两次单击期间, ViewHolder似乎仍处于滑动模式。

Or does someone have a better solution to lock a ViewHolder at a specific position while swiping so that buttons appear which can be clicked to either remove the ViewHolder or swipe the ViewHolder back to normal position? 还是有人有更好的解决方案,可以在滑动时将ViewHolder锁定在特定位置,以便出现可以单击以删除ViewHolder或将ViewHolder回到正常位置的ViewHolder

Consider using this github project - itemtouchhelper-extension . 考虑使用此github项目-itemtouchhelper-extension I got my all problem solved using that in my recent project. 我在最近的项目中使用它解决了所有问题。 Its is having pretty good implmenation example as well. 它也有很好的实现示例。 Try out. 试用。

I solved my problem by using following library: AndroidSwipeLayout 我通过使用以下库解决了我的问题: AndroidSwipeLayout

It is pretty simple to use. 使用起来非常简单。 Can recommend it to everyone who needs to work with "locked RecyclerView items". 可以将其推荐给需要使用“锁定的RecyclerView物品”的每个人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM