I have some problem with animation on RecyclerView
I have chat list with lot of messages. Each message is removing with delay (20s) and animation fadeout(0.3s). All work fine but it look strange sometime. Because if message is removing then all item below going up during first item is removing (fadeout). It looks like cumulative views on first position.
I am thinking about start animation before remove item. But it is not good idea. Also I thought about combining removing animation with scrolling the removing view.
One thing you can do is animate/collapse the height of the item view from its full height to 0, then remove the item from the adapter and refresh after that animation is complete.
Related
This is a question regarding the use of Android Transition API.
I am trying to animate the height change of a list, just like a dropdown menu.
I tried 2 approaches
Use a RecyclerView and animates its height change
Use a ScrollView > LinearLayout hierarchy and animates ScrollView's height.
The 2nd approach works perfectly.
But the 1st approach has a serious glitch - when the collapse transition starts, items disappear immediately.
By looking at the below GIF you can observe clearly the difference:
To be exact, items' visibility changes at the moment I change RecyclerView's LayoutParams, without waiting for the transition to finish, whatever it is expanding or collapsing
Code
I have created a minimal project on Github.
If you just want to look at the code, here is the MainActivity.
Question
Is it possible to achieve ScrollView's effect with a RecyclerView?
If yes, how?
My Idea is to do the transition of all the recycler view rows individual rather than the whole RecyclerView:
So when collapsing iterate through each ROW of a RecyclerView and do a transition. Remember to check for null if some rows are recycled they may return null. So after that collapse the whole recyclerView.
And like wise for the expanding do the same for the views.
This issue is cause by RecyclerView has many views with it but Scroll View has only one View nested in it.
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.
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 can I animate adding new item or moving item from one position to another in listview? I want to make animation effect, like in this app: any.do(youtube). I'm using adapter extended from ResourceCursorAdapter. How I should use newView and bindView functions to achieve this effect? Or is there another way to do it, like extending ListView class? I suspect that there is a ScrollView instead of Listview in any.do app. But I think this is wrong way, if you will have many items in list. Any ideas?
To do that effect, you need to:
1. "close" the slot where the item used to be.
2. "open" a slot in the list, where the item will "land".
3. Move the item between the slots.
To achieve the first animation, you need to animate the list item view itself. To make it disappear, you can animate the value of its bottom margin. I wrote a blog post about other Animation I did in Any.DO, where I animated this value - http://udinic.wordpress.com/2011/09/03/expanding-listview-items/. You can use the same animation to animate list item's view.
The "open" animation is the same as the close, but in the opposite direction. You take the list item, positioned right before your "landing point", and animate its bottom margin outwards, making an empty space for the new item to come.
Moving the item between the positions is fairly easy. You need to inflate a view with the same layout as the list items, populate it with the current item's data, add it to the WindowManager:
WindowManager winManager = (WindowManager) Context.getSystemService(Context.WINDOW_SERVICE);
winManager.addView(..)
and animate it's coordinates by using:
winManager.updateViewLayout(..);
After the animation will finish - you can remove this view and refresh the list.
The Add item animation is done using the same concept.
Sorry I don't have full source to provide here. At my blog post you can find the code for the expand/close animation.
Hope this helps!
I have animation in one listview item. After scrolling list when list item with animation started not visible I am scrolling back to the listview item with animation but animation doesn't work anymore.
getView() method :
iv.setImageResource(R.drawable.anim);
iv.requestFocus();
((AnimationDrawable) iv.getDrawable()).start();
?
UPDATE:
Is it wrong question or there are not any ideas?
You are assuming that every time the view is been scrolled(or become visible to you), the animation will start playing. But it's not true, the view can be not visible an yet be in the memory, so when you are scrolling it and it become visible, the getView() method will not be called. This is why it is a bad practice to put animations inside a list. I suggest you to implement the entire view by yourself if this is something you most to do.