0

When my recyclerview gets a new item inserted using notifyItemInserted and smoothScrollToPosition, it creates a flickering/blink effect. What is causing it? I just want it to scrollDown when a new item is inserted.

 mMessageList.add(messageObject);
 runOnUiThread(new Runnable() {
 @Override
 public void run() {                            
       mChatMessageAdapter.notifyItemInserted(mMessageList.size());                    
       mRecyclerView.smoothScrollToPosition(mMessageList.size());                            
     }
 });
Santanu Sur
  • 10,997
  • 7
  • 33
  • 52
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
  • 3
    You can follow this link. It would be helpful. https://stackoverflow.com/questions/47250907/recyclerview-scroll-to-position-when-a-new-item-is-added – Mukta Ghosh Oct 29 '19 at 07:18
  • @MuktaGhosh Thanks for the link. Apparently I was missing "-1" at the end of smoothScrollToPosition(mMessageList.size()). That fixed that flickering problem – DIRTY DAVE Oct 29 '19 at 07:27
  • Yes you are. Welcome. – Mukta Ghosh Oct 29 '19 at 07:54
  • 1
    `notifyItemInserted` also should have -1, and also `smoothScrollToPosition` should be made inside some `post` giving some time for `notifyItemInserted` to work (it may need to draw this new item if you are on the bottom) – snachmsm Oct 29 '19 at 08:23

0 Answers0