Recyclerview not scrolling to end when keyboard opens

前端 未结 10 1377
有刺的猬
有刺的猬 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:07

    You can catch keyboard up changes using recyclerview.addOnLayoutChangeListener(). If bottom is smaller than oldBottom then keyboard is in up state.

    if ( bottom < oldBottom) { 
       recyclerview.postDelayed(new Runnable() { 
           @Override 
           public void run() {
               recyclerview.smoothScrollToPosition(bottomPosition); 
           }
        }, 100);
    }
    

提交回复
热议问题