I'm trying to create a Recyclerview that will scroll to the top first and then animate the addition of an item onto the recyclerview.
This is the code I have so far:
while (!mLayoutManager.isSmoothScrolling()) {
mRecyclerView.smoothScrollToPosition(0);
}
PostList.add(0, post);
mAdapter.notifyItemInserted(0);
mAdapter.notifyItemRangeChanged(1, PostList.size());
This does scrolls to the top but the addition of the item is not animated (although it is added to the list).
I think it is because the addition animation occurs at the same time as the smoothScrollToPosition
animation and therefore when it has reached the top, the addition animation is already finished so we cannot see it.
I can use a Handler.postDelayed
to give my scroll animation some time to finish, but that is not preferable as I don't know the time that the smoothScrollToPosition
animation will finish.