Android 列表视图和动画
我正在使用API演示中的listview动画,示例2。以下是OnCreate方法的代码片段:Android 列表视图和动画,android,android-listview,android-animation,Android,Android Listview,Android Animation,我正在使用API演示中的listview动画,示例2。以下是OnCreate方法的代码片段: 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.addAnimati
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.0f,
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);
在将来的某个时候,notifyDataSetInvalidated()
被调用到列表的适配器上,并且我的列表被刷新。但这些项目不再显示在动画中
请提供帮助。您应该查看此帖子(更新链接以指向Romain Guy的答案!) 简言之,区别在于:
:数据集中的项目已更改(添加/删除/更新/重新排序,无论什么)李>notifyDataSetChanged
:适配器的数据源不再可用notifydatasetvalidated
您可以找到一个使用了
notifyDataSetValidated
函数的工作示例。可能它也可以解决动画问题。如果要在数据集更改后重新激活LayoutController,请调用视图的方法。这适用于视图组。例如,如果我想在回收的视图上重放动画,我不能调用view.startayOutAnimation()。它不存在