androidandroid-recyclerviewwindow-soft-input-mode

Android: Recycler view is not scrolling to last position


I am trying to create a chat screen by using the Recycler view. Because of chat when ever user enter to the screen the list should scroll to last position.

My problem is when keyboard open the list is hiding. If we use adjust pan, entire view is going to up, I trying to scroll only the list, I want title bar remain same position when the keyboard open


Solution

  • Add this to your code and check....It works fine for me....

    mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener()
    {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) 
        {
            if (mRecyclerAdapter != null) 
            {
                if (bottom < oldBottom) 
                {
                    mRecyclerView.smoothScrollToPosition(mRecyclerAdapter.getItemCount() - 1);
                }
            }
        }
    });
    

    Add this line to when you get new message....

    mRecyclerView.smoothScrollToPosition(mRecyclerAdapter.getItemCount() - 1);