本文共 828 字,大约阅读时间需要 2 分钟。
要实现这个效果,只需要再适配器getView之前,给每个条目的view设置相应的动画即可。
首先需要2个动画的xml文件。
在res下新建anim文件夹:(res/anim)
第一个动画xml文件:
up_from_bottom.xml
down_from_top.xml
在listview的适配器中使用定义的动画:
代码如下:
private int lastPosition = -1;@Overridepublic View getView(int position, View convertView, ViewGroup parent) { //Load your view, populate it, etc... View view = ...; Animation animation = AnimationUtils.loadAnimation(getContext(), (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top); view.startAnimation(animation); lastPosition = position; return view;}
参考: http://kylewbanks.com/blog/Implementing-Google-Plus-Style-ListView-Animations-on-Android
If you are interested the animation,
you can check out the full source on , or download the project and try it out.
转载地址:http://bibcl.baihongyu.com/