在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. MVC设计模式与JavaWEB三层架构

    一.MVC设计模式 MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controlle ...

  2. 搭建ELK日志分析平台(上)—— ELK介绍及搭建 Elasticsearch 分布式集群

    笔记内容:搭建ELK日志分析平台(上)-- ELK介绍及搭建 Elasticsearch 分布式集群笔记日期:2018-03-02 27.1 ELK介绍 27.2 ELK安装准备工作 27.3 安装e ...

  3. Coding上部署Ghost博客

    Ghost构建于Node.js平台之上.支持0.10.*版本号的Node.js. 在你的本地计算机上执行Ghost事实上非常easy,前提是你已经安装了Node.js. 什么是Node.js? 略过 ...

  4. Android实现天气预报温度/气温折线趋势图

     Android实现天气预报温度/气温折线趋势图 天气预报的APP应用中,难免会遇到绘制天气温度/气温,等关于数据趋势的折线或者曲线图,这类关于气温/温度的折线图,通常会有两条线.一条是高温线,一 ...

  5. [BLE--Link Layer]设备蓝牙地址

    简述 不论什么网络设备而言,都会有自己独特的一个MAC地址,不然在设备量较大的情况下非常可能造成通信的混乱.蓝牙是无线通信中使用非常广泛的技术.当然其蓝牙地址也是相当的重要的了. 蓝牙地址简述 种类划 ...

  6. ubuntu 交叉编译qt 5.7 程序到 arm 开发板

    ubuntu 交叉编译qt 5.7 程序到 arm 开发板平台1 ubuntu 12.042 arm-linux-gcc 4.5.13 QT 5.74 开发板210 armcortex-A8 一 概述 ...

  7. angular4(2-2)angular脚手架引入第三方类库(swiper)

    试了好多方法,npm install 方法失败了,下载到本地是可以使用的: 将swiper文件放到assets文件下: 项目目录下:(命令行) 因为ts并不能准确识别js语法,所以需要用ts中的int ...

  8. JSP中动态include与静态include的区别介绍

    转自:https://m.jb51.net/article/43304.htm 动态INCLUDE 用法:<jsp:include page="included.jsp" f ...

  9. xBIM 高级01 IFC多模型合并

    系列目录    [已更新最新开发文章,点击查看详细]  多模型合并可以实现以下功能: 覆盖多个模型以表现得像一个模型 统一访问数据,就像它是单个模型一样 只读.要修改模型的内容,您必须使用特定模型 不 ...

  10. C#的常见算法(面试)(转)

    一.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m //方法一,通过顺序规律写程序,同时也知道flag标志位的重要性. static int F1(int m) { ; ...