3

I'm using a LinearLayoutManager to create a horizontally aligned RecyclerView. Since I'm drawing out of the items' bounds, the overlapping drawings from the outer left and right neighbors disappear during scrolling because the views get recycled.

Is there a way to instruct the Adapter or LayoutManager to always keep x + 2 views?

I expected RecyclerView.setItemViewCacheSize( int size ) to solve this for me, but the views still appear to be detached.

Taig
  • 6,718
  • 4
  • 44
  • 65
  • The Adapter turns data into views. It doesn't choose when or which views should be visible at any one time. Does one item overlap the next item? Is it possible for your views not to extend beyond their bounds? Perhaps an image will help. – Andrew G Sep 16 '15 at 12:15
  • Yes, they are overlapping. Each item contains a `View` with a width of 125%. This view serves the purpose of drawing the background, a `ShapeDrawable` in the form of an arrow. The desired layout is comparable to the breadcrumbs in this screenshot http://designmodo.com/wp-content/uploads/2012/06/622.jpg – Taig Sep 16 '15 at 12:35
  • Nevermind, I found a simple visual trick to get around my specific problem. I'll leave this question open, though. There are valid use cases where it would make sense to control this behavior and it would lead to a cleaner to solution of my problem. – Taig Sep 16 '15 at 13:00
  • @Taig How did you resolve this, I'm having the very same issue. I am also trying to disable children clipping and achieve the same effect. – SadeepDarshana Jun 28 '17 at 10:01
  • 1
    @SadeepDarshana I'm unfortunately no longer able to comprehend the problem and its solution. All I can see from the code is that the item padding is playing a key role to solve that. – Taig Jun 28 '17 at 22:01
  • I was able to achieve the expected effect by making the RecyclerView and the other overlapping View TRULY overlap(by keeping them in the same space in a RelativeLayout instead of doing this by clipChildren=false) and then assigning a header(or footer) of the same size as the other overlapping View to the RecyclerView – SadeepDarshana Jun 29 '17 at 06:25

2 Answers2

0

You can't draw outside the bounds of a RecyclerView using LinearLayoutManager and expect the view to keep drawing once its bounds leave the bounds of the RecyclerView.

You should phrase your problem better. You gave little detail and wanted someone to help you to make your inappropriate solution work.

You should add RecyclerView.ItemDecoration before every view except view 0. e.g. https://gist.github.com/alexfu/0f464fc3742f134ccd1e

Why add the divider before each view? because then we don't need to change the last view back and forth between having a divider after it or not when we add/remove breadcrumbs. That's less work and better performance.

Andrew G
  • 2,596
  • 2
  • 19
  • 26
0

This does not answer the 'keeping n+1 Views attached problem', but the very problem about drawing out of the RecyclerView's bounds

The same effect of drawing out of the bounds can be obtained like this.

Make the RecyclerView and the other overlapping View TRULY overlap(by keeping them in the same space in a RelativeLayout instead of doing this by clipChildren=false which is merely a visual illusion).

Assign a header View(or footer depending on whether the other View is on top or bottom) of the same size as the other overlapping View to the RecyclerView.

(on adding headers Views RecyclerView header and footer)

SadeepDarshana
  • 1,057
  • 18
  • 34