timusus / RecyclerView-FastScroll

A simple FastScroller for Android's RecyclerView
Other
1.39k stars 183 forks source link

Issue with items with different height #55

Closed hosseinaminii closed 6 years ago

hosseinaminii commented 7 years ago

Hello I have 3 types of view in my RecyclerView with different heights. In my case RecyclerView-FastScroll dose not work correctly. Is it possible to fix it?

Thanks

timusus commented 7 years ago

That's what MeasurableAdapter is for.

hosseinaminii commented 7 years ago

I used MeasurableAdapter but it still does not scroll smoothly.

timusus commented 7 years ago

You'll need to be more specific.

MarcosCirilo commented 7 years ago

The MeasurableAdapter isn't working correctly. I did implemented the "getViewTypeHeight" like you did in sample project and the fast scroll still working wrong.

timusus commented 7 years ago

Can you please provide an example? The thing I'm having trouble with is 'it's not working' which doesn't really tell me much about the problem.

I didn't write the measurable adapter aspect of this project, so I'm not able to just imagine how you're using it and in which way it's not working.

Feel free to post some code, or provide a fork which demonstrates the problem.

MarcosCirilo commented 7 years ago

I'm using a recycler view with two view types, each view type has a different height. My adapter implements MeasurableAdapter and implements the method "getViewTypeHeight".

@Override public int getViewTypeHeight(RecyclerView recyclerView, int viewType) { if(viewType == adapter.VIEW_TYPE_ITEM){ return recyclerView.getResources().getDimensionPixelSize(R.dimen.favorites_heigth); } else{ return recyclerView.getResources().getDimensionPixelSize(R.dimen.sections_heigth); } }

When i run the project and test the fast scroll the screen is shaking. Every time that a view with sections height start appear at screen bottom the screen shake and the thumb loses the correct position.

marverenic commented 7 years ago

I was able to reproduce this by creating an adapter with interwoven view types of different heights (i.e. an adapter where even rows have a height of 100dp and odd rows have a height of 50dp). It's caused by FastScrollRecyclerView.scrollToPositionAtProgress(...) not taking the MeasurableAdapter into account when it computes the view to scroll to.

I'll go ahead and open a PR once I've gotten this fixed.

yeahia2508 commented 7 years ago

I have a Recycleview header Item with 40dp height and other Items height are dynamic. What I have to do in this case?