so here is my setup:
I have a listview with a custom adapter and i have methods which add new items to the list from the top. This works without an issue but i am looking to tweak it and make it better.
so here is my issue: right now when i call notifyDataSetChanged() the items are added to the list but that happens instantly and it is kinda rough and you can't really see which items have been added.
what i want to do is actually have some sort of animation when the items are added so it appears like the old ones are pushed down and that be visible to the user (maybe last 300 ms per item or 2 seconds for a total of maybe 5-10 items)
Thanks for any help you can give me.
You can try to make tween animation for the listView. But I am not sure whether only new or all items are going o be animated when notifyDataSetChanged is called
Related
Wanna implement the filling of my ListView with the effect like that: the first item rotates X and fades in, later the second one and so on.
One way to do it is clear - add items one by one to the adapter (just like in that post), while the animations are handled by LayoutTransition object, which I set in advance.
However, I have a strange feeling, like it'd be somewhat a crutch to add items asycnchoniously just in sake of animation effect. Does anybody know how to do it better?
UPD:
Some details: I want items to be animated only when the underlying data changes, for instance, the server sends new info and the list updates, just like the old departure boards in airports.
Use a LayoutAnimationController....
LayoutAnimationController lac = new LayoutAnimationController(AnimationUtils.loadAnimation(getActivity(), R.anim.table_row_appear), 0.5f); //0.5f == time between appearance of listview items.
listView.setLayoutAnimation(lac);
Whenever you want to run the animation :
listView.startLayoutAnimation();
Finally, I ended up with using the LinearLayout instead of ListView because of the view reusage, that reruns the animation for every view whenever it's showed up again.
But I did it just because I didn't have too many items to show. Another approach, as I guess, is to load animations in adapter, compute delay in accordance with item position and to store the map with the info, wether the view has already been animated in or not.
You can create an animation(transition + fade or any other effect you want) and add the animation to the Layout (view) that you return in "getView"
the animation shall take in consideration the "position" parameter to create the delay when the animation is started.
enjoy
daniel
I am having trouble finding the event to bind in the ListView adapter to scroll the listview to the bottom when a new item is added. When I initially populate the list its scrolled to the bottom which is correct but on an subsequent adds to the lists via a polling service it doesn't seem to stay on the bottom and I am forced to manually scroll. I am just wondering what events I need to hook into in order to set the index or automatically scroll to the bottom.
Okay I just noticed that when I add another item it pushes up 1 so it seems 1 item is always hidden when I add a new one, not quite sure how to fix this.
After doing more research I realised the error was due to me updating the collection on a different thread. Needed to be on the UIThread.
https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/Working%20With%20Collections/Collections.Droid/Views/PolymorphicListItemTypesView.cs
When I remove an item from a gridview, it fades out (because I start an animation) and all the other items change their place "at once".
Is there a simple way to animate all the other items to move, so the empty spot get filled up nicely animated, and not "at once"?
I would like to do the same for adding a new Item: all existing items will move animated and make a free place at the start of the grid where the new item will appear. I could of course do this by animating every item on itself, doing something different for the items at the end of a line, etc. But I would think there is already something prepared for this?
I checked out http://developer.android.com/reference/android/view/animation/GridLayoutAnimationController.html
But that only seems to be useful for showing the grid come into view, not when it already is in view.
Also, if you know an open source program that implemented this, please let me know.
This helped me a lot, you can at least use the animations in this project, but maybe the whole thing will suit you:
https://github.com/mrKlar/PagedDragDropGrid
example on youtube here:
http://www.youtube.com/watch?v=FYTSRfthSuQ
It looks like a gridview but isn't a gridview object. I used some of the code to change my own (android) gridview, but that was a great deal of work. If you can, just use this whole project.
I have an issues, I want to show 20 items in the list.
But there is a catch: if the user scrolls down to the bottom of the list, there will be an item that says: "Show more items", and when the users click on it, more items will be added to the list.
My question is how is poosible to have a last item, that has a different style and looks different: and does different things,(I think this is used in QuickSearchbox)
If you still want a clickable item rather than an infinitely scrolling list you can try using ListView#addFooterView to add your "Show more items" item. This lets you add a view as the last item in a list. Make sure you call it before calling setAdapter.
I would recommend you commonsware's cwac-endless.
cwac-endless: Provides the
EndlessAdapter, a wrapper for an
existing ListAdapter that adds
"endless list" capability. When the
user scrolls to the bottom of the
list, if there is more data for this
list to be retrieved, your code gets
invoked in a background thread to
fetch the new rows, which then get
seamlessly attached to the bottom of
the list.
While commonware has some awesome stuff. His endless lib may not be what you want. What you probably want is a footer. On your ListView, before you set your adapter, call addFooterView. Note that if you do that, the adapter you get from ListView.getAdapter will not be the same as what you passed to ListView.setAdapter.
Edit
Speaking of commonware, he sells a few books on his site. Buy them. They are the best $40 you will spend on your android education.
In the layout below the listview you can put a linear layout with "Clear" and "Get More Results" buttons. Not exactly what you are asking but it can achieve the same result.
My app polls a server every 15 seconds to see if there are any new items to display, then downloads the new items and disposes of the old items so that there are always exactly 100 items in the GridView. Unfortunately, this process can be confusing to the user if they see a page of images change without knowing where the items went.
My idea is that there could be some kind of animation (such as the new items being inserted at the top and pushing the older ones down the list) to show what action is happening. Unfortunately, I have no clue how to make this animation happen.
Is my idea even possible? How would I accomplish this?
Ben,
I know it's been almost a year since you posted this question. But I thought this might help you out.
http://developer.android.com/reference/android/view/animation/GridLayoutAnimationController.html
I think you will have to extend this layout and somehow pass in the position of the changes.
There are like 10 animations examples in the sdk (you will have to download them using the updates manager); the example is called "API demos". First, you can take a look of the Views -> animations examples... though, in your case the more interesting ones can be found in Views -> LayoutAnimatons.