三种动画的简单用法——学习笔记
2017-10-11 21:19
387 查看
AlphaAnimation——透明度渐变动画
ScaleAnimation ——缩放动画
RotateAnimation——旋转动画
①ScaleAnimation动画相关方法的参数:
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromX 动画起始时 X坐标上的伸缩尺寸
float toX 动画结束时 X坐标上的伸缩尺寸
float fromY 动画起始时Y坐标上的伸缩尺寸
float toY 动画结束时Y坐标上的伸缩尺寸
int pivotXType 动画在X轴相对于物件位置类型
float pivotXValue 动画相对于物件的X坐标的开始位置
int pivotYType 动画在Y轴相对于物件位置类型
float pivotYValue 动画相对于物件的Y坐标的开始位置
②RotateAnimation动画相关方法的参数
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐标的伸缩值。
int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐标的伸缩值。
以下是一个简单的例子
布局界面代码为:
Activity代码为:
下面是运行图片
ScaleAnimation ——缩放动画
RotateAnimation——旋转动画
①ScaleAnimation动画相关方法的参数:
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromX 动画起始时 X坐标上的伸缩尺寸
float toX 动画结束时 X坐标上的伸缩尺寸
float fromY 动画起始时Y坐标上的伸缩尺寸
float toY 动画结束时Y坐标上的伸缩尺寸
int pivotXType 动画在X轴相对于物件位置类型
float pivotXValue 动画相对于物件的X坐标的开始位置
int pivotYType 动画在Y轴相对于物件位置类型
float pivotYValue 动画相对于物件的Y坐标的开始位置
②RotateAnimation动画相关方法的参数
RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
参数说明:
float fromDegrees:旋转的开始角度。
float toDegrees:旋转的结束角度。
int pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotXValue:X坐标的伸缩值。
int pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。
float pivotYValue:Y坐标的伸缩值。
以下是一个简单的例子
布局界面代码为:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/splash_bg" android:id="@+id/splash_root"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_laugh" android:layout_centerInParent="true"/> </RelativeLayout>
Activity代码为:
public class SplashActivity extends AppCompatActivity { private RelativeLayout splash_rl_root; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); splash_rl_root = (RelativeLayout) findViewById(R.id.splash_root); //动画 AlphaAnimation aa = new AlphaAnimation(0, 1); //渐变动画 //aa.setDuration(500); //持续播放时间 aa.setFillAfter(true); //动画结束后保持状态 ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); //缩放动画 //sa.setDuration(500); sa.setFillAfter(true); RotateAnimation ra = new RotateAnimation(0, 360, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); //旋转动画 // ra.setDuration(500); ra.setFillAfter(true); AnimationSet set = new AnimationSet(false); //是否加速 //添加三个动画没有先后顺序 set.addAnimation(aa); set.addAnimation(sa); set.addAnimation(ra); set.setDuration(2000); //同时设置播放时间 splash_rl_root.startAnimation(set); //同时播放三个动画 set.setAnimationListener(new MyAnimationListener()); //给动画设置一个监听 } class MyAnimationListener implements Animation.AnimationListener{ /* 当动画开始播放的时候调用 */ @Override public void onAnimationStart(Animation animation) { } /* 当动画播放结束的时候调用 */ @Override public void onAnimationEnd(Animation animation) { Toast.makeText(SplashActivity.this, "动画播放完成!", Toast.LENGTH_SHORT).show(); } /* 当动画重复播放的时候调用 */ @Override public void onAnimationRepeat(Animation animation) { } } }
下面是运行图片
相关文章推荐
- cocos2d-x学习笔记04:简单动画
- php——学习笔记,圆周率的三种书写方法看float用法
- cocos2d-x学习笔记04:简单动画
- cocos2d-x学习笔记1:简单动画
- 学习笔记(二)FreeMarker简单用法
- 【学习笔记】tableview 简单用法,加图片,文字数组,锁定不滚动
- 转载自马哥视频学习笔记---Linux Web服务器网站故障分析常用的命令之awk用法的简单示例
- Ext.Net学习笔记19:Ext.Net FormPanel 简单用法
- cocos2d-x 2.0 学习笔记--简单动画
- 黑马程序员之C#学习笔记: new关键字的三种用法
- HTML5学习笔记之Video视频简单用法
- Unity Cinemachine插件学习笔记,结合Timeline实现简单场景动画
- 数据库学习笔记---connect by的简单用法(转载)
- RadioGroup的RadioButton简单用法——学习笔记
- 温故而知新--Linux学习笔记(二)实用的简单命令的简单用法
- Spark学习笔记-SparkStreaming简单用法
- 3DMAX学习笔记——Animate简单的动画
- 《Spring+Mybatis》Mybatis简单注解配置的用法学习笔记与代码
- 数据库学习笔记---connect by的简单用法
- 学习笔记:Silverlight 三种动画 图片截取 循环给二维数组赋值