Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ItemTouchHelper make dragged item go over fragment footer

Tags:

android

I have a RecyclerView with an ItemTouchHelper. The RecyclerView is a 2/2 grid and it has a header and footer on the page. When the user picks up an item I want that item to be able to hover over the footer. However, I do not want the other items in the recycler view to be able to be seen through the footer.

So first I tried adding clipChildren and clipPadding but that created a situation where the RecyclerView items were scrolling up through the footer which was a problem. I tried adding elevation to the item and bringToFont but those never worked because the recycler view was still behind the footer, I tried adding bring to front to the recycler view itself but then once again all the items become in front of the footer again instead of just the dragged one, does anyone have any other ideas on how to solve this?

like image 336
Adam Katz Avatar asked Mar 03 '17 10:03

Adam Katz


1 Answers

I would start by making sure your recycler view has android:clipChildren="false". That way you should not need the recyclerview to be literally overlapped by the footer - it can end above the footer and still allow it's children to draw outside of bounds.

If you have a static footer you can try calling bringToFront when you determine y axis has moved far enough that your current item intersects the footer. Then when you move back out of range or when the recyclerview scrolls at all, bring the footer back to the front. However this would be particularly error prone; a bit of a hack.

Edit:

A different approach would be to completely sever the connection between a dragged item and the recyclerview (this will take a bit of work on the drop part), the steps would roughly be:

- Start dragging item i
- store a reference to i.getParent() and the view index within its parent
- i.getParent().removeView(i) //detach the item from the recycler (or create clone)
- layout.addView(i) //add item onto main layout containing footer, allowing overlap

- when dropped, use the parent reference and index to reattach the item
- then work out where the item was released
like image 62
Nick Cardoso Avatar answered Sep 21 '22 15:09

Nick Cardoso