I have a recyclerview list with items like this:
The red square only can we swiped (drag and drop out) to the left, and the green only can we swiped to the right. When the element is swiped, appear and image with a option like this:
-swipe left:
The layout item have this appearance:
<RelativeLayout>
<LinearLayout>
<ImageView/> //Red square
<ImageView/> //Green square
</LinearLayout>
<LinearLayout>
<ImageView/> //Red square swiped action
<ImageView/> //Green square swiped action
</LinearLayout>
</RelativeLayout>
I'm trying to do this with ItemTouchHelper.Callback
and overriding the method onChildDraw
to make the correct animation. But I can't hold with square has be swiped, and make the correct animation. ¿Another way to achieve this?
Based on a lot of examples, it's easy by creating you own Callback listener in RecycleView. Just as in this example . You need to provide you own behavior.
Example of SimpleItemTouchHelperCallback from link above.
@Override
public int getMovementFlags(RecyclerView recyclerView, ViewHolder viewHolder) {
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
//Four your Red field use flags
int redFlags = ItemTouchHelper.START;
//Four your Green field use flags
int greenFlags = ItemTouchHelper.END;
return makeMovementFlags(dragFlags, swipeFlags);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.