devunwired / recyclerview-playground

Examples of RecyclerView use and custom LayoutManager implementations
MIT License
1.24k stars 269 forks source link

Marking views recyclable algorithm when in fling state #20

Closed liao123abc closed 8 years ago

liao123abc commented 9 years ago

Dear Dear Dave Smith:

Great job!

But could you please help me about some cofusions?

Currently I dive into your code of the FixedGirdLayoutManager, it confused me.

To make it simple, suppose it only scroll vertically.

When slowly scrolling,RecyclerView will tell the manager to do something by : scrollVerticallyBy()

and then detach all the views then calculate the visible rows and columns then find the right child views that are still in the visible area. If no view is ready for the slot, then create a new one.

This is understandable.

But with a fling gesture, it seems that the the old and new created child views are positioned in a quite large negtive Pos by:

old views: 1.offsetChildrenVertical(delta); in scrollVerticallyBy() of fixedGridLayoutManager

new views: 2.layoutDecorated(); in fillGrid() of fixedGridLayoutManager

I have log them out,Plz have a look at the log :

layoutDecorated.png: layoutdecorated

offsetChildrenVertical.png: offsetchildrenvertical

This confused me for a long time , I cannot figure it out: When fling the recyclerview vertically bottom up;

  1. Why we need to position the child view from a large negtive position in the y-axis , for exeample: -1766 while my recyclerView height is : 1293. Isn't the position -1766 deem bo be invisible to my recyclerview? Then why have to attach view from here?
  2. I noticed that when scrolling down, if the bottom of the fist view in the recyclerView is negetive, you will increase the mFirstVisiblePosition by 1 to mark that view is recyclable. This marking recyclable algorithm is a little hard to understand. Why only mark the top row of child views recyclable. How dose it work?

Please, I beg for your answers. I have been confusing by these questions for a long time.

devunwired commented 9 years ago

I need a bit more information here. Your layoutDecorated() numbers don't make sense to me. It's note entirely clear what I'm looking at in that log. You mentioned it was during a fling upwards, but what line of the FGLM code is being logged there?

If the first number in each row is the adapter position (just a guess), then the bottom values should increase with each row (y-coordinate is positive in the downward direction), but they get more negative as the position number goes up. So either this log is a concatenation of different snippets in a way that I cannot work out, or one of these values is being logged incorrectly.