Search code examples
androidandroid-recyclerviewswipeitemtouchhelper

How show custom layout under swiped RecyclerView item?


I want after swiped RecyclerView item to get my custom layout on the background. And I found a solution to which leads a lot of links. But I have problems using it.

Reference to the solution - https://stackoverflow.com/a/35667044/8013212

If you do exactly the same as in the example, then everything works. But in the example the clipBackground is aligned on the left side, and I need to center. Any attempts to change the alignment of the clipBackground cause it to stop displaying. Please tell me how to align the clipBackground in the center?


Solution

  • It's all about the way the layout is rendered. It uses not the coordinates, but the boundaries of the drawing, where 0/0 is the upper-left corner of the screen.

    In the solution, clipBackground is placed on the right and drawn from the same location. Changing the alignment and the drawing side, when using backgroundView.setRight (0), causes the background layout to be placed outside the screen, or its width remains 0.