您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码:  验证码,看不清楚?请点击刷新验证码 必填



  求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Modeler   Code  
会员   
 
   
 
 
     
   
 订阅
  捐助
安卓第十八天笔记--简单动画
 
作者:森林森 来自于:博客园 发布于 2016-4-1
   次浏览      
 

title:动画

动画

1.补间动画

1.Animation.ABSOLUTE:用于指定后面的数值是绝对值的像素。

2.Animation.RELATIVETOSELF: 用于指定后面的数值是自己宽高的倍数

3.Animation.RELATIVETOPARENT : 用于指定后面的数值是自己的父控件宽高的倍数

4.Animation.RESTART播放重新回到原点

5.Animation.REVERSE播放回接着,反向播放

2.平移

fromXType 水平播放的类型

fromXValue 从哪开始,0表示现在的位置

toXType, 到什么位置的类型

toXValue 到什么坐标

fromYType 垂直播放的类型

fromYValue 从哪开始,0表示现在的位置

toYType 到什么位置的类型

toYValue 到什么坐标

TranslateAnimation translate = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, -2,
Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1);
//设置显示时间
translate.setDuration(3000);
//播放资源为无限循环
translate.setRepeatCount(Animation.INFINITE);
//播放模式,反转播放,先顺着播完,就反着播放
translate.setRepeatMode(Animation.REVERSE);
//哪个组件在播放,设置
imageView.setAnimation(translate);
//开始播放
translate.start();

3.旋转

/*
* fromDegrees, 从什么角度开始 0 从现在的 toDegrees, 270度 pivotXType, X中心点类型
* Animation.RELATIVE_TO_SELF自身 pivotXValue, 中心点值 0.5表示这个图片的一半置
* pivotYType, Y中心点类型Animation.RELATIVE_TO_SELF自身
* pivotYValue 0.5f
*/
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
3);
//播放显示时间
rotate.setDuration(5000);
rotate.setRepeatCount(Animation.INFINITE);
rotate.setRepeatMode(Animation.RESTART);

imageView.setAnimation(rotate);
rotate.start();

4.缩放

 /*
* fromX, toX, 从坐标什么地址开始到什么坐标,0,表示当前 fromY, toY,
* pivotXType, 旋转的中心点
* pivotXValue, 类型, pivotYType, pivotYValue
*/
ScaleAnimation scale = new ScaleAnimation(1, 2, 1, -2,
Animation.RELATIVE_TO_SELF, -2, Animation.RELATIVE_TO_SELF, 3);

// 播放显示时间
scale.setDuration(5000);
scale.setRepeatCount(Animation.INFINITE);
scale.setRepeatMode(Animation.RESTART);

imageView.setAnimation(scale);
scale.start();

5.透明度

/*
* fromAlpha, 从什么透明度开始
* toAlpha 到什么透明度结束
*/
AlphaAnimation alpha = new AlphaAnimation(1, 0);

// 播放显示时间
alpha.setDuration(2000);
alpha.setRepeatCount(Animation.INFINITE);
alpha.setRepeatMode(Animation.REVERSE);

imageView.setAnimation(alpha);
alpha.start();
}

6.集合

就是建立一个

AnimationSet set = new AnimationSet();
set.addAnimation(scale);
set.addAnimation(rotate);
set.addAnimation(translate);
set.start();

就可以播放多个动画

7. XML配置

在res/目录下建立anim文件目录

<!-- 
如果平移的数值是数字,那么表示的是绝对值
如果是百分比,那么表明是自己的宽高的倍数
如果是百分比加上 p,那么表明是自己的父元素的宽高的倍数
-->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<translate
android:fromXDelta="200%"
android:toXDelta="200%"
android:fromYDelta="-100%"
android:toYDelta="200%"
android:duration="4000"
android:repeatCount="infinite"
android:repeatMode="reverse"/>

<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="4000"
android:repeatCount="infinite"
android:repeatMode="reverse"/>

</set>

加载使用AnimationUtils.load方法加载

Animation animation = AnimationUtils.loadAnimation(this, R.anim.animation_set);
imageView.startAnimation(animation) 

8.属性动画

一般都用代码控制

/**
* 水平
*
* @param v
*/
public void translate(View v) {
/**
* 参数一: 谁去播放这个动画 参数二: 属性名字 想要改变x方向的移动 参数三:动画执行的数值
*/
ObjectAnimator objectAnimatrX = ObjectAnimator.ofFloat(imageView,
"translationX", -50, 50);
ObjectAnimator objectAnimatrY = ObjectAnimator.ofFloat(imageView,
"translationY", 0, 60);

objectAnimatrX.setDuration(2000);

objectAnimatrX.setRepeatCount(ObjectAnimator.INFINITE);

objectAnimatrX.setRepeatMode(ObjectAnimator.REVERSE);

objectAnimatrX.start();
}

/**
* 转换
*
* @param v
*/
public void rotate(View v) {
ObjectAnimator rotateX = ObjectAnimator.ofFloat(imageView, "rotationX", 0,360);
ObjectAnimator rotateY = ObjectAnimator.ofFloat(imageView, "rotationY", 0,360);
rotateX.setDuration(3000);
rotateX.setRepeatMode(Animation.REVERSE);
//rotateX.setRepeatCount(Animation.INFINITE);
rotateY.setDuration(3000);
rotateY.setRepeatMode(Animation.REVERSE);
//rotateY.setRepeatCount(Animation.INFINITE);

AnimatorSet set = new AnimatorSet();
set.playSequentially(rotateX,rotateY);
set.start();
}

/**
* 绽放
*
* @param v
*/
public void scale(View v) {
ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 2.0f,5f);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 2.0f,5f);
scaleX.setDuration(3000);
scaleX.setRepeatMode(Animation.REVERSE);
scaleX.setRepeatCount(Animation.INFINITE);
scaleY.setDuration(3000);
scaleY.setRepeatMode(Animation.REVERSE);
scaleY.setRepeatCount(Animation.INFINITE);

AnimatorSet set = new AnimatorSet();
set.playTogether(scaleX,scaleY);
set.start();
}

/**
* 透明
*
* @param v
*/
public void alpha(View v) {

ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 1.0f,0f);
alpha.setDuration(3000);
alpha.setRepeatMode(Animation.REVERSE);
alpha.setRepeatCount(Animation.INFINITE);

alpha.start();
}

/**
* 集合
*
* @param v
*/
public void set(View v) {
/**
* 参数一: 谁去播放这个动画 参数二: 属性名字 想要改变x方向的移动 参数三:动画执行的数值
*/
ObjectAnimator objectAnimatrX = ObjectAnimator.ofFloat(imageView,
"translationX", -50, 100);
ObjectAnimator objectAnimatrY = ObjectAnimator.ofFloat(imageView,
"translationY", -70, 100);

objectAnimatrX.setDuration(2000);

//objectAnimatrX.setRepeatCount(ObjectAnimator.INFINITE);

objectAnimatrX.setRepeatMode(ObjectAnimator.REVERSE);
objectAnimatrY.setDuration(2000);

//objectAnimatrY.setRepeatCount(ObjectAnimator.INFINITE);
objectAnimatrY.setRepeatMode(ObjectAnimator.REVERSE);

AnimatorSet set = new AnimatorSet();

//set.playTogether(objectAnimatrX,objectAnimatrY);
set.playSequentially(objectAnimatrX,objectAnimatrY);
set.start();
}

如果需要 用XML控制可以在res\下建立 animator,即可, 在这个目录建立XML文件如果 下方法导入

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
R.anim.property_animator);
set.setTarget(myObject);
set.start();
   
次浏览       
 
相关文章

手机软件测试用例设计实践
手机客户端UI测试分析
iPhone消息推送机制实现与探讨
Android手机开发(一)
 
相关文档

Android_UI官方设计教程
手机开发平台介绍
android拍照及上传功能
Android讲义智能手机开发
相关课程

Android高级移动应用程序
Android系统开发
Android应用开发
手机软件测试
最新活动计划
Node+Vue3.0前端全栈开发 7-5 [特惠]
Spring Cloud微服务架构 7-5[特惠]
SysML和EA系统设计与建模 7-26[特惠]
Python、数据分析与机器学习 8-23[特惠]
嵌入式软件架构设计 8-22[线上]
Linux内核编程及设备驱动 7-25[北京]

android人机界面指南
Android手机开发(一)
Android手机开发(二)
Android手机开发(三)
Android手机开发(四)
iPhone消息推送机制实现探讨
手机软件测试用例设计实践
手机客户端UI测试分析
手机软件自动化测试研究报告
更多...   

Android高级移动应用程序
Android应用开发
Android系统开发
手机软件测试
嵌入式软件测试
Android软、硬、云整合

领先IT公司 android开发平台最佳实践
北京 Android开发技术进阶
某新能源领域企业 Android开发技术
某航天公司 Android、IOS应用软件开发
阿尔卡特 Linux内核驱动
艾默生 嵌入式软件架构设计
西门子 嵌入式架构设计
更多...