博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android中对于非属性动画的整理
阅读量:4057 次
发布时间:2019-05-25

本文共 2675 字,大约阅读时间需要 8 分钟。

1.最常用的帧动画

xml实现:

调用:

//对于动画的调用//        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();//        animationDrawable.start();

代码实现:

AnimationDrawable animationDrawable1 = new AnimationDrawable();        for (int i = 1; i < 4; i++) {            int id = getResources().getIdentifier("pic" + i, "drawable", getPackageName());            Drawable drawable = getResources().getDrawable(id);            animationDrawable1.addFrame(drawable, 300);        }        imageView.setBackgroundDrawable(animationDrawable1);        //是否只是播放一遍        animationDrawable1.setOneShot(false);        animationDrawable1.start();
2.补间动画--渐变,翻转,平移,缩放

//补间动画-渐变        AlphaAnimation animation=new AlphaAnimation(0,1);//0表示头像1表示不透明        animation.setDuration(5000);        animation.setFillAfter(true);//动画结束后保留最后的状态        imageView.setAnimation(animation);        animation.start();
//补间动画-平移        //Animation.RELATIVE_TO_PARENT//相对于父布局,这需要是个百分比的数值,0到1        //Animation.ABSOLUTE//是一个准确的数值        //Animation.RELATIVE_TO_SELF//相对于自己的尺寸,这里也是一个百分比的数值,0到1        //注意,不管怎样,左边原点都是自身view的左上角        //int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue        TranslateAnimation translateAnimation=new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0.0f,Animation.RELATIVE_TO_PARENT,                0.8f,Animation.RELATIVE_TO_PARENT,0.0f,Animation.RELATIVE_TO_PARENT,0.6f);        //对于这个,注意,动画是从view自身的位置开始移动的,并不是从父布局的0,0坐标开始移动        translateAnimation.setDuration(5000);        translateAnimation.setFillAfter(true);        imageView.setAnimation(translateAnimation);        translateAnimation.start();
//补间动画-旋转,开始的角度,结束的角度,旋转中心在哪        //float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue        RotateAnimation rotateAnimation=new RotateAnimation(0f,270f,Animation.RELATIVE_TO_SELF,0.2f,Animation.RELATIVE_TO_SELF,0.2f);        rotateAnimation.setDuration(5000);        rotateAnimation.setFillAfter(true);        imageView.setAnimation(rotateAnimation);        rotateAnimation.start();
//补间动画-缩放        //和旋转类似,起始的xy尺寸比例,以及类似缩放中心的一个数据        //float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue        ScaleAnimation scaleAnimation=new ScaleAnimation(0,1.0f,0,1.0f,Animation.RELATIVE_TO_SELF,0.2f,Animation.RELATIVE_TO_SELF,0.2f);        scaleAnimation.setDuration(5000);        scaleAnimation.setFillAfter(true);        scaleAnimation.setRepeatCount(100);        imageView.setAnimation(scaleAnimation);        scaleAnimation.start();

转载地址:http://vfrci.baihongyu.com/

你可能感兴趣的文章
能源化工要怎么管控核心数据
查看>>
媒体广告业如何运用云盘提升效率
查看>>
企业如何运用企业云盘进行数字化转型-实现新发展
查看>>
司法如何运用电子智能化加快现代化建设
查看>>
iSecret&nbsp;1.1&nbsp;正在审核中
查看>>
IOS开发的开源库
查看>>
IOS开发的开源库
查看>>
Jenkins - sonarqube 代码审查
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成(一)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 单机部署(二)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 高可用集群部署(三)
查看>>
Golang struct 指针引用用法(声明入门篇)
查看>>
Linux 粘滞位 suid sgid
查看>>
C#控件集DotNetBar安装及破解
查看>>
Winform皮肤控件IrisSkin4.dll使用
查看>>
Winform多线程
查看>>
C# 托管与非托管
查看>>
Node.js中的事件驱动编程详解
查看>>
mongodb 命令
查看>>
MongoDB基本使用
查看>>