Change recyclerView scroll position reference

92 views Asked by At

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?

2

There are 2 answers

2
hamid Mahmoodi On

Your question is not clear enough! but I think clipToPadding = true and paddingBottom can solve your problem with recyclerView I understood your problem correctly

0
Mohammed Alramlawi On

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
}