在Android中listview是最经常使用的控件之中的一个,可是有时候我们会认为千篇一律的listview看起来过于单调,于是就产生了listView动画,listview载入了动画会让用户体验更好,本期就分享一些listview动画以及实现方法。效果图



相信大家都熟悉Android的Tween动画,前四种动画就是Translate,Alpha,Rotate,Scale,最后一种Rotate3d则是用了一个3D旋转动画工具类Rotate3dAnimation,这个类的构造函数中接收一些3D旋转时所需用到的參数。比方旋转開始和结束的角度,旋转的中心点等。

LayoutAnimationController能够控制一组控件依照规定显示。ListView中的mListView.setLayoutAnimation相信大家都知道是用来干什么的了。接下来上代码

	private Button button, button2, button3, button4, button5;
private ListView mListView;
private Animation animation;
private LayoutAnimationController controller;
private String[] arry = { "一", "二", "三", "四", "五", "六" };
private ArrayAdapter<String> adapter; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, arry);
mListView.setAdapter(adapter); } private void initView() {
// TODO Auto-generated method stub
mListView = (ListView) findViewById(R.id.list);
button = (Button) findViewById(R.id.btn_tran);
button.setOnClickListener(this);
button2 = (Button) findViewById(R.id.btn_alpha);
button2.setOnClickListener(this);
button3 = (Button) findViewById(R.id.btn_rotate);
button3.setOnClickListener(this);
button4 = (Button) findViewById(R.id.btn_scale);
button4.setOnClickListener(this);
button5 = (Button) findViewById(R.id.rotate3d);
button5.setOnClickListener(this);
} @Override
public void onClick(View arg0) {
// LayoutAnimationController.ORDER_NORMAL; 顺序显示
// LayoutAnimationController.ORDER_REVERSE;反显示
// LayoutAnimationController.ORDER_RANDOM; 随机显示
switch (arg0.getId()) {
case R.id.btn_tran:
animation = new TranslateAnimation(-50f, 0f, 0f, 0f);
animation.setDuration(500);
//1f为延时
controller = new LayoutAnimationController(animation, 1f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
mListView.setLayoutAnimation(controller);
adapter.notifyDataSetInvalidated();
break;
case R.id.btn_alpha:
animation = new AlphaAnimation(0f, 1f);
animation.setDuration(500);
controller = new LayoutAnimationController(animation, 1f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
mListView.setLayoutAnimation(controller);
adapter.notifyDataSetInvalidated();
break;
case R.id.btn_rotate:
animation = new RotateAnimation(0f, 360f);
animation.setDuration(500);
controller = new LayoutAnimationController(animation, 1f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
mListView.setLayoutAnimation(controller);
adapter.notifyDataSetInvalidated();
break;
case R.id.btn_scale:
animation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f);
animation.setDuration(500);
controller = new LayoutAnimationController(animation, 1f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
mListView.setLayoutAnimation(controller);
adapter.notifyDataSetInvalidated();
break;
case R.id.rotate3d:
animation = new Rotate3dAnimation(0, 360, 200, 200, 0, true);
animation.setDuration(1000);
controller = new LayoutAnimationController(animation, 0.1f);
controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
mListView.setLayoutAnimation(controller);
adapter.notifyDataSetInvalidated();
break;
default:
break;
} }

这样大家能够随心所欲的编写自己喜欢的动画效果

项目源代码

最新文章

  1. 项目开发之使用 maven
  2. vim 支持 markdown 语法
  3. Sublime Text 3 使用备注
  4. Oracle- 正则表达式查询
  5. hdu 1150 Machine Schedule (经典二分匹配)
  6. Win10命令大全通用(Win8,Win7)
  7. 基于ElasticStack数据分析应用系统
  8. IR2104s半桥驱动使用经验
  9. 报表工具highcharts使用心得
  10. java.lang.ClassCastException: net.sf.ezmorph.bean.MorphDynaBean cannot be cast to
  11. http://www.360doc.com/content/18/0406/16/15102180_743316618.shtml
  12. python爬虫常见面试题(二)
  13. 让apache支持htaccess文件
  14. 使用Java设计验证码生成程序
  15. mysql join实现方式
  16. 离散对数&amp;&amp;大步小步算法及扩展
  17. BBS项目之后台管理
  18. 【bzoj2929】[Poi1999]洞穴攀行 网络流最大流
  19. mysql 中sum (if()) 用法
  20. P3374 【模板】树状数组 1

热门文章

  1. Git学习总结(8)——Git和SVN之间的基本区别
  2. ASP.NET-HTTP管道模型
  3. spring mvc拦截器interceptor
  4. java io包File类
  5. UVALive - 2031 Dance Dance Revolution 三维dp
  6. iOS 常见小问题
  7. scanf使用与运算符
  8. 88.NODE.JS加密模块CRYPTO常用方法介绍
  9. [TJOI2017] DNA 解题报告 (hash+二分)
  10. 接入gitment为hexo添加评论功能