2

Layout to achieve

Hi I need to implement the layout as attached in pic. I have tried this StackOverFlow answer

but the resultant view get created as attached below Resultant layout

I need that bottom right corner to be above next cell of recyclerview.

Please suggest how can make top of the cell below previous cell.

Community
  • 1
  • 1
nitinkumarp
  • 2,120
  • 1
  • 21
  • 30

1 Answers1

2

It looks like you're close. The problems you're seeing here are:

  1. The offset you're using in the item decorator from the example you used isn't large enough - hence the black gaps
  2. The order in which your linear layout manager is stacking your views is from the top, which means that the row below will draw over the cell above.

To fix this, first, add a bit more offset to get rid of the black gaps.

Second, call setReverseLayout(true) on your LinearLayoutManager (can also be done via the constructor) - this will make it draw the bottom items first, so that the cells will draw above the cells below.

Also, you might want to play around with the elevation of the views to get that neat shadow effect, making sure that a row at index N will have a higher elevation than a row at index N+1. You could do this by calling myView.setElevation((getItemCount() - position) * SOME_DP_AMOUNT) when binding each view in your adapter.

Gil Moshayof
  • 16,633
  • 4
  • 47
  • 58
  • I did setStackFromEnd(true) but result was same. Only my recylerview scrolled to bottom. – nitinkumarp Dec 05 '16 at 11:23
  • try setReverseLayout(true)? Also, try the trick with elevations - it could solve your problem all together without playing around with stacking or reversing. – Gil Moshayof Dec 05 '16 at 11:25
  • I will try try your suggestion and get back to you. Thanks. – nitinkumarp Dec 05 '16 at 11:26
  • Thank you. setReverseLayout did the trick. But my 1st cell is getting cut from top and last cell has large space at bottom because of offset. I am trying to do some thing to avoid that. If you have any suggestion then please inform me. – nitinkumarp Dec 05 '16 at 11:34
  • As for your first problem, check that SO post you linked - look at the comments in the answer, it references that exact problem. As for your second problem, it's difficult to see why this is a problem without a screenshot... maybe add one? – Gil Moshayof Dec 05 '16 at 12:14