Recyclerview not scrolling to end when keyboard opens

前端 未结 10 1402
有刺的猬
有刺的猬 2020-12-04 16:19

I am using recylerview in my application and whenever new element is added to recyclerview, it scrolls to last element by using

recyclerView.scrollToPosition         


        
10条回答
  •  误落风尘
    2020-12-04 17:08

    I found the postDelayed to be unnecessary and using adapter positions doesn't account for when the recycler is scrolled to somewhere in the middle of an item. I achieved the look I wanted with this:

    recycler.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        if (bottom < oldBottom) {
            messageRecycler.scrollBy(0, oldBottom - bottom);
        }
    })
    

提交回复
热议问题