I'm trying to implement a ToDo list that contains a list and some other views below it on the activity page.
I am using a LinearLayout
for the entire page and a RecyclerView
for the list, alongside other views below the RecyclerView
(ImageView
, Buttons
...etc.)
Here's my final view hierarchy:
<LinearLayout>
<TextView />
<RecyclerView />
<Button />
<EditText />
<ImageView />
</LinearLayout>
I have implemented the RecyclerView
where I can add and remove items.
I am using a LinearLayoutManager
without specifying an ItemAnimator
so DefaultItemAnimator
is used.
Adding items to the list works as expected. My problem is that the page doesn't animate well when I remove an item from the RecyclerView
(by removing it from the dataset first then using RecyclerViewAdapter.notifyItemRemoved
).
What happens is that the entire page snaps first to adapt to the new RecyclerView
height, and then the RecyclerView
item remove animation completes, which makes the behavior of the page look weird since all the views below the RecyclerView
snap up while the deleted item fades out but hasn't lost its height yet, then the remaining RecyclerView
items (below the deleted item) scroll up, looking like they're sliding up from under a wall.
I tried to look for solutions on the web and couldn't find anything to solve my problem.
I have found this unanswered question describing the same problem. Please refer to it in case my explanation wasn't clear enough.
Anyone encountering the same issue? Any suggestions?
Thanks.
How to remove scroll effect from RecyclerView android? You can open or close it. Basically, you need to add android:overScrollMode=“never” line to your RecyclerView.
Adapters provide a binding from an app-specific data set to views that are displayed within a RecyclerView .
I had the same problem. In my situation just this line helped:
recyclerView.setHasFixedSize(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With