Is there a way to change the scroll counter reference of recyclerView to start from the center of the screen, and not from the beginning? So that, when I call linearLayoutManager.findFirstVisibleItemPosition() I get the position of the item in the screen center and not at the start of the screen?
Asked
Active
Viewed 87 times
2 Answers
0
Your question is not clear enough! but I think clipToPadding = true
and paddingBottom
can solve your problem with recyclerView I understood your problem correctly

hamid Mahmoodi
- 690
- 4
- 16
-
I am using recyclerView with horizontal layoutManager, and calling findFirstVisibleItemPosition() to return the first visible item, but I need a way to get the item at the middle of the screen. – Mohammed Alramlawi Sep 09 '21 at 18:21
-
So you have lastVisiablePosition via findLastVisibleItemPosition(), the middle item position is depend on your logic – hamid Mahmoodi Sep 13 '21 at 15:36
0
I have got the solution for this issue, I simply override getPaddingLeft(), getPaddingEnd() methods as below.
private fun setupLinearManager(context: Context) {
linearLayoutManager = object : LinearLayoutManager(context, HORIZONTAL, false) {
override fun getPaddingLeft(): Int {
return screenWidth / 2
}
override fun getPaddingEnd(): Int {
return screenWidth / 2
}
}
recyclerView.layoutManager = linearLayoutManager
}

Mohammed Alramlawi
- 11
- 1