7

I wish to be able to remove items from a listview in a way that will animate both the removed item and the items beneath it, in a similar way shown for the layoutAnimations demo in the API demos.

For example:

enter image description here

Here, I wish to remove item 1. The first animation will smoothly move item 1 to the right, and upon completion will smoothly animate all of the items below this item (including more items if exist) to the empty space that item 1 used.

The first animation was quite easy:

final TranslateAnimation animation = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
        TranslateAnimation.RELATIVE_TO_SELF, 1.0f, TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
        TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(500);
view.startAnimation(animation);

But how would I achieve the nice effect of the other items where I actually use a listView which recycles its items?

In the demo I've mentioned, they don't even use a listView. In my case it's quite problematic since I have a lot of items.

I've also noticed a similar post about this matter, but all I found about it is that you need to modify the listView code, but no real solution.

Incidentally, the minimal sdk is 9.

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Did you read this? http://stackoverflow.com/questions/3928193/how-to-animate-addition-or-removal-of-android-listview-rows – Amokrane Chentir Dec 23 '12 at 15:05
  • yes , and i've also written about it in the end of my post . :( – android developer Dec 23 '12 at 15:09
  • Sorry didn't see it. I am still convinced that you need to go deep into the source code of the ListView and looks for ways to tweak it. – Amokrane Chentir Dec 23 '12 at 15:18
  • I don't know how to do it, but maybe look at the source for the notification draw on anything >= 4.0. I don't see it working with SDK 9 when it comes to the item popping out directly under your finger. You may be able to activate a gesture to register a swipe on an item, but I don't see it happening as smooth as your probably want. That's just my 2 cents.. – burmat Dec 23 '12 at 15:40
  • what if i have the power of using newer APIs ? for lower APIs i won't show this animation ... – android developer Dec 23 '12 at 15:46
  • To me, I think it would be easier. I am trying to download the source now to see for myself (I have a lot of LVs that could use this feature). – burmat Dec 23 '12 at 15:53
  • i don't understand . you have a working solution for this using newer APIs ? – android developer Dec 23 '12 at 16:12
  • No, but if you look at versions >= 4.0, you can see that this effect is used. The best example of what I think you are describing can be found in the both notification bar and task manager (both of which MAY use ListViews to display this content). I am trying to get the source code now to investigate further because I would enjoy using this effect also. – burmat Dec 23 '12 at 16:37
  • wow thank you . if you find anything , please post it here . i think the notifications bar is a better start since it looks more android-ui-native. – android developer Dec 23 '12 at 16:47
  • I agree. It is going to take an hour or so to download the source, and I am working on a new computer so OS dependancies may slow me down. I will get back to you if I find anything promising. – burmat Dec 23 '12 at 16:52
  • Take a look at the Google [solution][1]. Here is a deletion method only. [1]: http://stackoverflow.com/questions/3928193/how-to-animate-addition-or-removal-of-android-listview-rows/25065458#25065458 – dimetil Jul 31 '14 at 17:39
  • @dimetil I think I tested it, and it had a rare crash. I don't remember if they fixed it. – android developer Jul 31 '14 at 21:31

1 Answers1

0

I've found a nice sample that does almost exactly what I wanted, but sadly it requires API 12 in order to run, plus I've succeeded to make it crash somehow.

the sample can be found here .

the website also has other nice samples and cool UI views for android as well .

Hopefully someone will be able to find a way to make it available for lower API levels , since the statistics still say that many have API 10 .


EDIT: links are dead. However, this is possible using RecyclerView. You can even have a swipe-to-remove feature, as shown here.

android developer
  • 114,585
  • 152
  • 739
  • 1,270