在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;
} }

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

项目源代码

Android ListView动画实现方法的更多相关文章

  1. Android ListView动画特效实现原理及源代码

    Android 动画分三种,当中属性动画为我们最经常使用动画,且能满足项目中开发差点儿所有需求,google官方包支持3.0+.我们能够引用三方包nineoldandroids来失陪到低版本号.本样例 ...

  2. Android ListView 单条刷新方法实践及原理解析

    对于使用listView配合adapter进行刷新的方法大家都不陌生,先刷新adapter里的数据,然后调用notifydatasetchange通知listView刷新界面. 方法虽然简单,但这里面 ...

  3. SOUI3.0仿Android插值动画使用方法

    在Android系统中,有插值动画,数值动画,属性动画,帧动画. 帧动画,在SOUI里可以通过AnimateImg这个控件来实现,其它几种动画3.0之前不支持,需要类似动画效果,只能自己通过定时器去实 ...

  4. (转)Android之常用功能方法大集合

    这些,都是Andorid中比较常用的方法和功能,在网上搜集整理一下记录之,以备不时之需.由于经过多次转载,源文作者不确凿,在此申明,敬请见谅.不得不赞,非常实用. 1.判断sd卡是否存在 boolea ...

  5. Android透明动画

    Android透明动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...

  6. Android旋转动画

    Android旋转动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...

  7. Android缩放动画

    Android缩放动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...

  8. Android平移动画

    Android平移动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...

  9. Android Animation动画实战(一): 从布局动画引入ListView滑动时,每一Item项的显示动画

    前言: 之前,我已经写了两篇博文,给大家介绍了Android的基础动画是如何实现的,如果还不清楚的,可以点击查看:Android Animation动画详解(一): 补间动画 及 Android An ...

随机推荐

  1. HDU 2155 Matrix

    Matrix Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 215 ...

  2. ASP.NET-Session与复杂数据类型

    原文链接:http://www.cnblogs.com/fish-li/archive/2013/05/28/3104750.html Session与复杂数据类型 Session有三种工作模式,拿A ...

  3. POJ 2183

    模拟题 #include <iostream> #include <cstdio> #include <algorithm> using namespace std ...

  4. Django连接mysql

    链接文档地址:https://docs.djangoproject.com/zh-hans/2.0/intro/tutorial02/ 由于我使用的是mysql,所以设置的是mysql的: 在mysl ...

  5. Activity管理笔记

    文章仅记录自己学习该模块时的一点理解,看到哪写到哪.所以特别散. AMS管理四大组件外加进程管理,当中最庞大的算是Activity了吧. 1.AMS中对ActivityStack划分为两类.当中一类是 ...

  6. nyoj--90--整数划分(母函数)

    整数划分 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 将正整数n表示成一系列正整数之和:n=n1+n2+-+nk,  其中n1≥n2≥-≥nk≥1,k≥1.  正整数 ...

  7. Dapper基础知识一

    在下刚毕业工作,之前实习有用到Dapper?这几天新项目想用上Dapper,在下比较菜鸟,这块只是个人对Dapper的一种总结. 1,什么是Dapper?     Dapper,.NET下的一种ORM ...

  8. python继承 super()

    写这篇博文,始于以下问题的探究: #coding:utf-8 class A(object): def __init__(self): print 'enter A' print 'leave A' ...

  9. C语言的常用printf打印占位符%d, %u, %f, %s, %c, %o, %x

    占位符含义及用法 代码: #include <stdio.h> int main(int argc, char const *argv[]) { , b = -; // 默认10进制赋值 ...

  10. Vue export和import

    config/index.js export default '123456'; import strs from '@/config';   //此处直接写@config就可以, 如果是export ...