Open jsonfellin opened 7 years ago
try to see --> #3
@chemickypes Thanks, yeah I did and it doesn't work reliably. The library should be able to set a default position (something like selectedIndex
), not scrolling by pixels.
@jsonfellin mh, sure, you're right! Did you try to use smoothScrollToPosition() method?
@chemickypes Yeah, see my first comment above.
@jsonfellin Hey thanx for pointing that out will try to fix it ASAP. And even I have experienced RecyclerView.smoothScrollToPosition() missing the given index.
@chemickypes hey man I am open for suggestion :sweat_smile:
@jsonfellin Oh sorry, I was confused! I have another question: when do you call this method? I had a similar problem: I put smoothScrollBy() method inside a OnGlobalLayoutListener when data is not already loaded and it's not working. So, I had to wait for the finish of notifyDataSetChanched().
try something like this -->
slimAdapter.notifyDataSetChanged();
post(new Runnable() {
@Override
public void run() {
//make your selection
//RecyclerView.smoothScrollToPosition()
}
});
@adityagohad we have to think about it!
@adityagohad In my project of HorizontalPicker I put a method in the custom LinerLayout manager :
public void select(int position) {
scrollToPositionWithOffset(position,10);
rv.smoothScrollBy(1,0);
}
The first method is inside LinearLayoutManager to scroll to the wanted position and the latter let RecyclerView to scroll (very tiny, 1 px) and select the element.
This method is called when you add data in the Horizontal Picker
public void addData(List<?> data, final int selectedItem){
slimAdapter.updateData(data);
post(new Runnable() {
@Override
public void run() {
selectItem(selectedItem);
}
});
}
...
public void selectItem(int position) {
try {
if (position < slimAdapter.getItemCount()) {
pickerLayoutManager.select(position);
}
} catch (Exception e){
e.printStackTrace();
}
}
I don't know if this idea can help @jsonfellin
@adityagohad Any fix for this issue yet?
Anyone can solve this issue ? Please give me solution
@nayankukadiya @paramarthasaha96 @jsonfellin
I tried to figure out how to solve this issue for a while and finally... i think, i found solution.
DONT HARDCODE RecyclerView padding, use dynamic padding adding
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int padding = (displayMetrics.widthPixels - VIEW_HOLDER_WIDTH_IN_PIXELS) / 2;
mRecyclerView.setPadding(padding, 0, padding, 0);
now, I can use smoothScroll on recycler and init position is ok. so, just play with paddings, guys.
p. s. thanks for amazing library!
@ReeMiXeR Doesn't that assume each view holder has equal width?
@adityagohad smoothScrollToPosition(*) launches animation, so it causes dragging when i launch my fragment (maybe it caused by centering of picked element). If i use scrollToPosition, i have static RV but without scaled items. How can i fix that?
I don't see a way to set the initial selected view or item. RecyclerView.smoothScrollToPosition() doesn't seem to scroll to the correct position. Any ideas?