Scroll RecyclerView up accordingly when keyboard opens

后端 未结 7 1915
情歌与酒
情歌与酒 2021-01-12 15:34

I have created a chat activity and like facebook messenger, there is an EditText at the bottom and above is the RecyclerView of messages. When Keyboard opens, I want to scro

7条回答
  •  不思量自难忘°
    2021-01-12 16:07

    recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                if ( bottom < oldBottom) {
                    recyclerView.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            recyclerView.scrollToPosition(adapter.getItemCount());
                        }
                    }, 100);
                }
            }
        });
    

    if it not work Use smoothScrollToPosition instead of scrollToPosition

    This is work for me.

提交回复
热议问题