1,首先我们看一下如下的代码

import android.view.animation.LayoutAnimationController;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.Transformation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.TranslateAnimation; private Animation myHistoryAnimation;
private LayoutAnimationController myLayoutControl;
private AlphaAnimation myHistoryAlphaAnimation;
private AlphaAnimation myHistoryAlphaAnimationConTime;
private TranslateAnimation myHistoryTranslateAnimation;
private AnimationSet myHistoryAnimationSet; myHistoryAlphaAnimation = new AlphaAnimation(1, 0);
myHistoryAlphaAnimationConTime = new AlphaAnimation(1, 1);
myHistoryAlphaAnimation.setDuration(1000);
myHistoryAlphaAnimationConTime.setDuration(500);
myHistoryAnimationSet = new AnimationSet(true);
/* Vanzo:zhangshuli on: Fri, 20 Mar 2015 14:57:37 +0000
* modify for v5 calculator
myHistoryTranslateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(
this, R.anim.history_clear_anim);
*/
myHistoryTranslateAnimation = new TranslateAnimation( Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,10f);
myHistoryTranslateAnimation.setDuration(1000);
// End of Vanzo: zhangshuli
myHistoryAnimationSet.setFillAfter(true);
myHistoryAnimationSet.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
history_clear_choose.setVisibility(View.GONE); } @Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
android.util.Log.e("zhangshuli", "set");
/* Vanzo:zhangshuli on: Fri, 20 Mar 2015 16:17:24 +0000
* modify for v5 calculator
if (mDrawerLayout.isDrawerVisible(GravityCompat.END)) {
mDrawerLayout.closeDrawer(GravityCompat.END);
}
*/
// End of Vanzo: zhangshuli }
});
myHistoryAlphaAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation arg0) {
mHistory.clear();
mLogic.onClear();
android.util.Log.e("zhangshuli", "tran1"); }
});
myHistoryAnimationSet.addAnimation(myHistoryTranslateAnimation);
myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimation);
myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimationConTime);
myLayoutControl = new LayoutAnimationController(myHistoryAnimationSet);
myLayoutControl.setDelay(0.1f);
// myLayoutControl.setOrder(LayoutAnimationController.ORDER_NORMAL);
myLayoutControl.setOrder(LayoutAnimationController.ORDER_REVERSE); mHistoryDisplayList.setLayoutAnimation(myLayoutControl);

2.从以上的代码中我们可以发现。代码中定义动画的话,有个好处,就是比较灵活,可以根据我们的需要动态的更改动画的时间等属性。当然,你也会看到它代码的重用性非常的糟糕。

1)创建动画:其实就是new一个相应的动画就行了

2)然后就是设置动画的属性值,时间等

   import android.view.animation.AlphaAnimation;   

  AlphaAnimation alphaAnimation=new AlphaAnimation( 1f,0.5f);
//动画时间
alphaAnimation.setDuration(1000);
//动画结束以后是否应用,false的话,会返回初始位置
alphaAnimation.setFillAfter(true);
//设置动画动作样式
alphaAnimation.setInterpolator(this,android.R.anim.accelerate_decelerate_interpolator);

其他的也类似

import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
TranslateAnimation translateAnimation = new TranslateAnimation(
//第一个参数:相对于父类还是自身比例 第二个其实x坐标
Animation.RELATIVE_TO_SELF, 0f,
//起始y坐标
Animation.RELATIVE_TO_SELF,0f,
//结束x坐标
Animation.RELATIVE_TO_SELF,0f,
//结束y坐标
Animation.RELATIVE_TO_SELF,10f);

3)如果你仅仅就需要一个简单的动画,那么你只需要在一个控件上start这个动画就行了,如下

view.startAnimation(myAnimation_Alpha);

4)如果你希望把几个动画进行复合,这时候你需要借助

myHistoryAnimationSet = new AnimationSet(true);
 myHistoryAnimationSet.addAnimation(myHistoryTranslateAnimation);

AnimationSet 其实就相当于一个动画容器,可以把不同的动画效果合为一个复合动画进行

animation- 动画效果实现(代码中)的更多相关文章

  1. Android中xml设置Animation动画效果详解

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

  2. android中设置Animation 动画效果

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

  3. 模仿百度首页“元宵节汤圆”动图,并实现360°不停旋转(CSS3的animation动画效果)

    模仿百度首页“元宵节汤圆”动图,并实现360°不停旋转(CSS3的animation动画效果) 效果图: 切图地址: https://ss1.bdstatic.com/5eN1bjq8AAUYm2zg ...

  4. 右上角鼠标滑过展开收缩动画效果js代码的演示页面

    http://files.cnblogs.com/files/tanlingdangan/top_right.rar.gz 右上角鼠标滑过展开收缩动画效果js代码的演示页面http://www.51x ...

  5. android Animation 动画效果介绍

    Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动 ...

  6. ios animation 动画效果实现

    1.过渡动画 CATransition CATransition *animation = [CATransition animation]; [animation setDuration:1.0]; ...

  7. Android Animation动画效果简介

    AlphaAnimation 淡入淡出动画  <alpha>A fade-in or fade-out animation. Represents an AlphaAnimation. a ...

  8. Animation(动画效果)

    Ctrl+6打开Animation窗口.选择物体,点击录制,保存录制文件后即为给该物体添加了动画效果. Animation可以修改某时间点的物体位置.大小.材质球上的所有属性.碰撞器等等. 可以通过修 ...

  9. H5中需要掌握的 ANIMATION 动画效果

    CSS3的动画在PC网页上或者APP上用得越来越多,比如H5页面的应用,目前在营销传播上的意义比较大,还有企业官网或者APP主要介绍也用得比较多,当然还有很多地方都用到.所以学习css的动画也迫在眉睫 ...

  10. UITableview reloadData Animation 动画效果

    http://blog.kingiol.com/blog/2013/10/22/uitableview-reloaddata-with-animation/ 运用到UITableview进行重新加载数 ...

随机推荐

  1. shrio int配置

    之前章节我们已经接触过一些INI配置规则了,如果大家使用过如Spring之类的IoC/DI容器的话,Shiro提供的INI配置也是非常类似的,即可以理解为是一个IoC/DI容器,但是区别在于它从一个根 ...

  2. Sandbox

    Sandbox Contents Overview Design principles Sandbox windows architecture The broker process The targ ...

  3. 打印机共享为什么老是出现“操作无法完成(错误 0X00000709)。再次检查打印机名称、并确保打印机连接网络

    这个情况应该是访问IP连接打印机才会出现的.解决办法:不使用IP访问,使用网上邻居找计算机名称再连接打印机即可. ------------------------------------------- ...

  4. MySQL Field排序法

    检索 id = 2 or id = 5 or id = 9 or id = 56 or id = 38.然后按照 2 , 5, 9, 56, 38 这个顺序排列,这是题目要求   以下为解决方案: 1 ...

  5. LRJ入门经典-0905邮票和信封305

    原题 LRJ入门经典-0905邮票和信封305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 假定一张信封最多贴5张邮票,如 ...

  6. Mysql学习总结(5)——MySql常用函数大全讲解

    MySQL数据库中提供了很丰富的函数.MySQL函数包括数学函数.字符串函数.日期和时间函数.条件判断函数.系统信息函数.加密函数.格式化函数等.通过这些函数,可以简化用户的操作.例如,字符串连接函数 ...

  7. nagios插件之登陆防火墙实现session监控

    ssh_firewall_session.sh -- 登陆防火墙并运行dis session statistics firewall_check_sessions.c -- 调用上面脚本.过滤出ses ...

  8. PAT-中国大学MOOC-陈越、何钦铭-数据结构基础习题集 00-自測4. Have Fun with Numbers (20) 【二星级】

    题目链接:http://www.patest.cn/contests/mooc-ds/00-%E8%87%AA%E6%B5%8B4 题面: 00-自測4. Have Fun with Numbers ...

  9. 如何分解json值设置到text文本框中

    <td><input type="text" id="name11"></td> //4设置访问成功返回的操作 xhr.on ...

  10. Nabou应用实例

      本文接上文 <完整性检查工具Nabou> http://chenguang.blog.51cto.com/350944/280712650) this.width=650;" ...