Open khrsantiago opened 2 years ago
Hello, thank's for putting up a feature request! It's awesome to see people using the library :D
I want to make sure I'm understanding your request correctly. Your smooth scroller is already working, and scrolling items to the center of the RecyclerView's layout? Now you just want to find the adapter index associated with the item at the center of the RecyclerView's layout?
Hello, thanks to you for creating this library, it saved me a lot problems, because I was trying to implement a RecyclerView with loop. 1) Yes, it's working and center to the RecyclerView. 2) Yes, I can find the position when I click on the item, but not when I scroll to the item.
I'm going to add a GIF with the RecyclerView https://user-images.githubusercontent.com/82970886/142652409-205eb5e9-73fd-46b7-911f-8ed49e9cbcbd.mp4
I was traying to do somthing like this: https://github.com/adityagohad/HorizontalPicker But this library dosen't have loop.
Hmm @IndustriasBJT do you think taking the average of the topLeftIndex and the bottomRightIndex could work for you?
I think so, how can I do that?
You should just be able to do:
val midIndex = (myLayoutManager.topleftIndex + myLayoutManager.bottomRightIndex) / 2
If that doesn't work give me a ping and we can try to work out a different solution =)
It work!, but I made some changes:
Java Code:
int topLeftIndex = layoutManager.getTopLeftIndex();
int bottomRightIndex = layoutManager.getBottomRightIndex();
int centerIndex = (topLeftIndex + bottomRightIndex) / 2;
if (topLeftIndex == dataList.size() - 1) centerIndex = 0; // To get the first element
if (bottomRightIndex == 0) centerIndex = dataList.size() - 1; // To get the last element
Toast.makeText(context,
"Left: " + topLeftIndex +
"\nRight: " + bottomRightIndex +
"\nCenter: " + centerIndex , /* Item Position */
Toast.LENGTH_SHORT).show();
It work!, but I made some changes:
Java Code:
int topLeftIndex = layoutManager.getTopLeftIndex(); int bottomRightIndex = layoutManager.getBottomRightIndex(); int centerIndex = (topLeftIndex + bottomRightIndex) / 2; if (topLeftIndex == dataList.size() - 1) centerIndex = 0; // To get the first element if (bottomRightIndex == 0) centerIndex = dataList.size() - 1; // To get the last element Toast.makeText(context, "Left: " + topLeftIndex + "\nRight: " + bottomRightIndex + "\nCenter: " + centerIndex , /* Item Position */ Toast.LENGTH_SHORT).show();
dataList it's a simple ArrayList of numbers, and I want to know is there any way to use any funtion like onStopClickListerner o onItemClikckListener, because I get the position of the element by clicking on the TextView of the adapter class.
BTW: Thanks for the solution 😃
Heya @IndustriasBJT :D Happy to help! I'm glad you found a solution that works for you. :sunflower:
I want to know is there any way to use any funtion like onStopClickListerner o onItemClikckListener, because I get the position of the element by clicking on the TextView of the adapter class.
I'm not sure if I'm understanding your question correctly. Are you asking if the LoopingLayoutManager supports those functions?
:key: Use case
I want to use this funtion to find the item position in the center of my Horizontal RecyclerView
:hammer: Proposal
N/A
:wrench: Alternative
N/A
:memo: Other info
I'm using a custom smoothScroller to center the items: https://stackoverflow.com/a/53756296)
:bee: Request for assignment
If possible, I would like to implement this.
I'm just requesting this feature. I don't want to implement it.