RecyclerView does not consider translation when processing views

I am playing with RecyclerView right now and came across the following problem. When the RecyclerView LinearLayoutManager decides whether the screen is off (so it can be a processor), it does not take into account the type of translationY .

So essentially, when I scroll up and I have views with positive translationY , LinearLayoutManager thinks the view is turned off, but in fact it is still visible (because it is downward).

I noticed that the LinearLayoutManager method makes this decision - it views getDecoratedBottom(View) , so I tried to override getDecoratedBottom(View) to enable translation. Unfortunately, he completely confused the layout - this method is also used when composing new elements, so new elements receive an additional translation (over the existing one).

Is there an easy way to tell LinearLayoutManager look at the translation attribute when it decides to view the recirculation without re-implementing the LayoutManager from scratch?

+6
source share
1 answer

Maybe it will be useful to someone, I found a solution.

Firstly, I tried to use Translate animation without any luck. But then I just created a new class extending ItemDecoration . Then override getItemOffsets() and set the correct offset to Rect. The LayoutManager successfully calculates these offsets. The achieved result is on the attached image.

0
source

Source: https://habr.com/ru/post/989046/


All Articles