开发者

Listview and animation

开发者 https://www.devze.com 2023-02-24 22:23 出处:网络
I\'m using listview animation from API DEMOS, example 2. here\'s the snippet from OnCreate method: ListView listview = (ListView) findViewById(android.R.id.list);

I'm using listview animation from API DEMOS, example 2. here's the snippet from OnCreate method:

ListView listview = (ListView) findViewById(android.R.id.list);

AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(50);
set.addAnimation(animation);

animation = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0开发者_运维问答f,
    Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);

animation.setDuration(200);
set.addAnimation(animation);

LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
listview.setLayoutAnimation(controller);

At some point in the future, notifyDataSetInvalidated() is called upon list's adapter, and my list is refreshed. but the items are not shown in animation any more.

Please help.


If you want to reanimate your LayoutController after your data set changes, call the method startLayoutAnimation() of the view.


You should check out this thread about difference between notifyDataSetChanged() and notifyDataSetInvalidated() (Link updated to point to Romain Guy's answer!)

In short the difference is:

  • notifyDataSetChanged: The items in the data set are changed (added / removed / updated / reordered, whatever).
  • notifyDataSetInvalidated: The data source of the adapter is no longer available.

Here you can find a working sample with notifyDataSetInvalidated function in use. Probably it will do the trick with your animation problem as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号