devunwired / recyclerview-playground

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

FixedTwoWayFragment snaps to origin on item click and view manipulation #26

Open manishkumar opened 8 years ago

manishkumar commented 8 years ago

In case of just one extra element (invisible) in a row and manipulating sub views on click causes it to snap to the first element. Here is the video showing it and here is the source code that is used the video

I hide one the row item sub views(home score textview). If I do not hide the textview and only change its value it works fine. Also if there are more than one (1) elements off the screen it works fine.

I went through the source code of FixedGridLayoutManager and it turns out this code is responsible for snapping.

if (getChildCount() == 0) { //First or empty layout
    //Reset the visible and scroll positions
    mFirstVisiblePosition = 0;
    childLeft = getPaddingLeft();
    childTop = getPaddingTop();
} else if (!state.isPreLayout()
        && getVisibleChildCount() >= state.getItemCount()) {
    //Data set is too small to scroll fully, just reset position
    mFirstVisiblePosition = 0;
    childLeft = getPaddingLeft();
    childTop = getPaddingTop();
} 

It goes into the else if block and resets position.

Also while calculating mVisibleColumnCount and mVisibleRowCount you add 1, any particular reason for that?

mVisibleColumnCount = (getHorizontalSpace() / mDecoratedChildWidth) + 1; mVisibleRowCount = (getVerticalSpace()/ mDecoratedChildHeight) + 1;