RecyclerView remove animation bug - android

I have implemented a RecyclerView where I can add and delete items. I want the added item to be added on the second last position and, whenever I add a new item, the animation runs well. That is, the last item moves downwards, letting space for the new item to fade in.
When I remove an item there is a problem that I don't know how to fix. How I want it to behave is:
fade out the deleted element,
move upwards all the items below it.
What actually happens is that, first thing, the last item disappears, and then the rest of the animation takes place. When the items below the deleted element move upwards, the last item reappears as coming from behind a wall.
To me it seems as if the RecyclerView shrinks to the "post-animation" height, and then the animation is performed.
I haven't defined the ItemAnimator, so the DefaultItemAnimator must be the one used. I have watched this video, and overridden the supportsPredictiveItemAnimations method in a custom implementation of LinearLayoutManager, but it doesn't fix it.

I already reported the problem through Google Issue Tracker here
I hope we can get a fix soon! As you say It seems very related to a possible race condition between the measure updates for the recyclerview and the animation when your recyclerview is wrapping it's content to calculate it's height.
This article explains the problem in a really detailed way also.

Perhaps a bit late, but I was able to fix this in my situation by setting the RecyclerView item animator to null, and then in the setList(list) function of my Adapter scheduling a Transition as such:
Transition transition = new AutoTransition();
transition.setDuration(200); // Or any duration you want
TransitionManager.beginDelayedTransition(mRootViewGroup, transition);
where mRootViewGroup is the viewgroup containing the RecyclerView.
This problem is also fixed by setting your layout_height (or width, depending on the scrolling orientation) to something other than wrap_content, but if, like me, you need your recyclerview height set to wrap_content, this might be a solution for you.
Not certain it will fix your problem as well, but I figured I might as well share what worked for me.

Related

Add background image to RecyclerView that moves with scrolling

I am trying to add background images, partially covered, to a scrollable view that move along with it. What's the best way to do that?
Below is my attempt. I created an image item, and set the item just below the image to have a negative offset at the top by using ItemDecoration. However, as you can see, the item suddenly appears and disappears.
My second idea is just to lump the image and first item into one single item, but that seems less clean. Anybody has some good suggestions?
Okay, I solved the sudden appearance/disappearance problem by giving the RecyclerView a -150dp layout_marginBottom. Now the recycler view extends below the screen and the first item persists until it goes offscreen. I then set 150dp paddingBottom to compensate for content loss at the bottom.
Now everything works perfectly. But I consider this approach a little hacky, and would love to see more ideas

Underscroll in RecyclerView android

I am creating a custom scroll inside RecyclerView and I did most of the work already but now I came to hopefully one of the last problems.
On scrolling, I am expanding/collapsing rows as they move up or down. It works fine until I reach the bottom of the list. Two items remain in their normal state because I can no longer scroll down and therefore they will not expand.
My question is, how can I scroll under the recyclerView when I reach the bottom? Do I need to implement onTouch listener and do the work from there? Or is there something in RecyclerView that can help me create the underscroll?
You should be able to expand them in onOverScrolled, as that will be called at the correct time to trigger their expansion.

Android RecyclerView Removing Item - 2 Animation Issues

When I click on a row in a vertical list RecyclerView, I call remove the item from the backing list, and call adapter.notifyItemRemoved(position). When position == 0 the move animation is called, otherwise remove animation is called.
In both cases, after that animation is called, an add animation is called for all other visible items on the screen. This makes the remove animation look bad, because all other items flash while the remove animation is being run.
Anyone know what could be causing that?
That does not make sense.
If you remove item at 0 (assuming it is visible and top item), there would be a "remove" for that item and "move" animation for all other visible views + one more (the new item to fill the new space but it comes with a move animation from below the list).
Can you post some code?
I was using TwoWayView (github.com/lucasr/twoway-view). I've had too much trouble with it, and removing it seems to have fixed any trouble I was having, including this issue.
Filed an issue with the project on Github here.

How to force start animation if view out of window

I have a scroll view with several views and only one view can be expanded. When another view gets expanded the already expanded view gets shrunk. But the animation for the not visible item on the screen gets started only when the view gets visible.
So is there a way to force start the animation?
Setting the height for not visible item causes unwanted jumping of scroll Y if the view is on top and view on bottom gets expanded.
I had the exact same problem and was so happy, that i found the question on SO, only to find out that no one had answered it. I looked around for a solution but didnt really find one. So what i did in the end was to check if the item was in the visible area (was pretty easy for me, since i used a custom pager) and set the animation time on the invisible items to 0.
Worked for me, but i dont know if this will work/worked for you.
PS: I would have posted a comment instead of an answer but i think i am not allowed yet.
Since nobody knowing this, I must assume this cannot be done.
You just invalidate the invisible view by invalidate() method.

Android listview (array adapter) custom scrolling

I would like to change the default behaviour of my listview, so when im scrolling to the last item, the list will keep scrolling untill the last item is at the top of the list.
default behaviour stops scrolling when the last item is fully in view.
Any ideas on how i can go about this pre 2.3?
Thanks,
Totem.
In case anyone is interested in the solutions available it either:
1) add to the list view padding, that solution forces you to play around with the fading edge property since it gets sifted because of thee padding. also this method might not work well if your using a transparent background because items will be rendered and visible under the padding area. Although this could be fixed by entering the list into a relative layout and making sure to draw something over that area.
2) add transparent items to the listview for offset and not set them as enabled to avoid dividers, just need to make sure to change getItemCount and getItemTypeCount and so on if your if your item isn't really inside your adapter as per my case.
I went with option two.
Thanks,
Totem.

Categories

Resources