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. Weka中数据挖掘与机器学习系列之基本概念(三)

    数据挖掘和机器学习 数据挖掘和机器学习这两项技术的关系非常密切.机器学习方法构成数据挖掘的核心,绝大多数数据挖掘技术都来自机器学习领域,数据挖掘又向机器学习提出新的要求和任务. 数据挖掘就是在数据中寻 ...

  2. Sqoop1与Sqoop2的比较

    1.sqoop1和sqoop2是两个不同的版本,它们是完全不兼容的. 2.版本划分方式:Apache 1.4.x 之后的版本属于sqoop1,1.99.x之上的版本属于sqoop2. 3.与sqoop ...

  3. Python(四) 分支、循环、条件与枚举

    一.什么是表达式 表达式(Expression)是运算符(operator)和操作数(operand)所构成的序列 二.表达式的优先级 三.表达式优先级练习 优先级同级 从左往右计算 1 or 2 a ...

  4. 将本地的代码上传到网上SVN库

    使用VisualSVN Server创建版本库: https://jingyan.baidu.com/article/db55b609f6aa724ba20a2f6c.html 最详细的教程: htt ...

  5. OPENCV(2) —— Basic Structures(一)

    DataType A primitive OpenCV data type is one of unsigned char, bool,signed char, unsigned short, sig ...

  6. Json与JsonPath

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,因为它良好的可读性与易于机器进行解析和生成等特性,在当前的数据整理和收集中得到了广泛的应用. JSON和XM ...

  7. 直接修改Android软件数据库来改变软件设置实例一则

    昨天把K860i刷了机,刷到了最新的CyanogenMod 10.1,使用起来各种流畅舒服,不过却由于内外置SD卡的挂载点的改变,造成了一些困扰,现记录如下.         平时里由于极少把手机连接 ...

  8. 【Uva 307】Sticks

    [Link]: [Description] 给你最多n个棍子; (n< = 64) 每根棍子长度(1..50) 问你这n根棍子,可以是由多少根长度为x的棍子分割出来的; x要求最小 [Solut ...

  9. linux杂谈(十八):DNSserver的配置(一)

    1.DNSserver简单介绍 域名系统(英文:Domain Name System,縮寫:DNS)是因特网的一项服务. 它作为将域名和IP地址相互映射的一个分布式数据库,可以使人更方便的訪问互联网. ...

  10. 用MediaRecorder实现简单的录像功能

    思路:定义一个SurfaceView用来显示预览,在SurfaceHolder的回调中用Camera对象启动预览.然后调用MediaRecorder来录像.仅仅是实现了简单的录像開始和停止功能.顶部能 ...