RecyclerView whole view animation when adding viewitem - android

I faced a problem recently, as we know when we add a item to recycle view, we can set item animation when add,update or remove.
The item animation has two steps, it's separated.
Move old view items.
Start add item animation.
So question is, I need the whole recycle view execute the item animation or merge these two steps to one step, such as the new added item and old view item move up together.

The animation is automated and combine both of yours. You have to add the new item and call the notifyInsertItem method and after that the scrollToPosition method.
The animation should work fine

Related

RecyclerView animation when for replacing entire DataSet

So I was working with RecyclerView animations, and implemented an animation for when the items load into the List. I was wondering, if I can make an animation for when I replace the entire data set (an animation including the items joining and leaving the RecyclerView).
The correct way to remove an item from a recycler view is to remove the item from the data set and them inform the adapter that the item is removed. If you do this then the animation would happen similar to the animation that happens when you add an item.
myDataset.remove(position); // myDataset is List<MyObject>
mAdapter.notifyItemRemoved(position);//this line is important
If you are not using the second line then...
mAdapter.notifyDataSetChanged()
will be called and the animation will stop.

How to get whole scroll event when removing element from adapter of recyclerview?

I'm trying to create "sticky headers" on a RecyclerView (which uses a LinearLayoutManager) but now I'm facing a problem. When I click on one item of the list, a new item is automatically inserted just below it and the RecyclerView's default animation is shown (the one which smoothly adds and shows the new item). When I tap the initial item again, this new added item is removed, and the RecyclerView's default animation is shown again (the one to slowly hide the removed item).
I have completed all the sticky headers functionality but now my problem is that when I click the last list item and the hide default animation is shown (with a scroll up), my sticky headers don't work. I need to know (and here is were I'm stuck) how to get notified while this RecyclerView animation is being performed when adding/removing items. I need to get notified with all the animation steps, not only the start and end ones.
So far I've tried to use a RecyclerView onScrollListener and a ViewTreeObserver (attached to the added/removed view) but neither worked. If someone could give me some help, it would be really appreciated.
Thanks in advance to all the Stack Overflow community

Animate RecyclerView additions from bottom

I am using the latest RecyclerView library to display a list with an option to add items to this list. The list is in reverse order, so newest additions are displayed at the bottom. When adding new items to a recycler view from the top, a nice animation is displayed and the list is automatically scrolled to display the newest item.
However, when adding new items from the bottom, items are not similarly pushed up as the new item is being animated. This leads to odd behavior where a new item is added and the animation cannot be seen unless the user scrolls to the bottom of the list.
As a temporary fix, I've forced the recycler view adapter to scroll to the first position after adding a new item. This isn't as seamless as adding from the top of a recycler view, is there a proper way to implement this?
The corresponding code is below:
la.addItem(0, msg);
layoutManager.scrollToPosition(0);
Add this function to your adapter class
public void addItem(Object aObject)
{
mAdapterList.add(aFormElement);
notifyItemInserted(mAdapterList.size()); // Passing position where insertion happen
}
If you are not getting animation than only use below function.
try to call scroll to position on recyclerview at your required position after calling addItem().

How to animate item in ListView when being clicked?

I want to have one ListView that when I click on the item the view slide out to the left.
So I have:
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
arg1.startAnimation(openAnimation);
}
});
However, animation applied to the different item in the list instead of the one being clicked on. The behavior seems to be random as sometime it happened to more than one item at the same time.
As I suspected this is because of the way Adapter reuse it's view to create item. I went to modify the getView method in my Adapter to inflate new view every time it's being called. Then the animation doesn't happen any more.
Is there a way to resolve this? I tried to move the animation to inside my Adapter but then I can not associate it with other action on the Listview.
Ultimately, I want the item to be clickable but when swipe left/right reveal delete button (iOS delete behavior). Am I on the wrong track here? This should be possible though as Android can implement swipe to remove in the Notification bar.
I recommend that you check this thread also.
I don't think, that this is possible without having to modify your adapter to suit this type of behavior. For what I understand, you don't have any problems with implementing the code recognizing the swipe gestures on different ListView-rows, only with the animation the should follow this gesture on according row(s).
I'd rewrite the adapter to suit at least 2 row types: normal rows, and rows to be deleted. In the "getView()" method of your adapter, you should only reuse the convertView of normal Views. Rows that are to be deleted should not reuse them, so that animating one would not modify the others.
Upon clicking a normal row, you should first tell the adapter that the row on the clicked position is now of type to-be-deleted, call .notifyDatasetChanged(), and then start the animation on that row.

Problem with ExpandableListView position

I have a "Dynamic" ExpandableListView. That is to say child are only load when there is click on there parent.
So I use onGroupExpand to load list. It works but I must expand myself the group with
expandableList.expandGroup(groupPosition);
The problem is that, when I click on parent, the group expands but the view go back to the first position. That is to say : I scroll, I click on parent, group expand, view go back to the first parent, so I must scroll again to see the group I click before.
I try to use expandableList.scrollTo(x,y); But it doesn't work.
I am having a similar problem. I found this method that lets you scroll based on an item position :
mList.smoothScrollToPosition(pos);
The downside is I have to call this from my groupClickListener() and in order to get it to work I have to put it inside of a runnable and delay it by part of a second otherwise it will do nothing. This means my list scrolls one way then stops and scrolls back to where it was, which looks weird. But its the only thing I've come up with thus far.

Categories

Resources