android动画效果的基础设置

一、动画的分类(两类或三类)
1、View Animation 视图动画 :只是实现动画效果,对view本身的属性并未影响
(1)Frame 帧动画
(2)Tween 补间动画
2、Property Animation 属性动画:通过动画的变化效果执行改变当前view的属性 sdk3.0之后出现

二、具体介绍:
1、Frame 帧动画
app中应用场景:页面未加载出来之前的动画效果
使用步骤:
(1)在res/drawable/下创建根标签为 animation-list 的xml文件,设置动画需要展示的所有图片:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@mipmap/girl_1" android:duration="100"></item>
..................
<item android:drawable="@mipmap/girl_11" android:duration="100"></item>
</animation-list>

animation-list 表示执行动画的列表
android:oneshot 表示如果指定为true 表示animation-lis标签中的动画执行一次
如果指定false表示item中的动画一直循环
android:drawable="@mipmap/图片名称" android:duration="" 表示帧动画中播放的时间毫秒值
(2)在activity中:
//设置当前的图片的资源为帧动画的xml文件
iv.setBackgroundResource(R.drawable.frame_animation);
//调用ImageView的控件的getBackground()方法,获取AnimationDrawable对象
AnimationDrawable drawable= (AnimationDrawable) iv.getBackground();
开始动画: drawable.start();
停止动画: drawable.stop();

2、补间动画(主要针对view视图): 改变后的图片的位置不会发生改变
补间动画可以实现四种效果
(1)淡入淡出 :对透明度的改变
(2)缩放:对控件的宽高尺寸进行改变
(3)平移:对控件的位置进行改变
(4)旋转:对控件的位置进行改变
补间动画共有的属性:
android:duration="时间的毫秒值" 设置动画的持续时间
android:fillAfter="true" 指定为true表示动画结束时维持在最终的状态 默认恢复到原始状态
android:repeatCount="infinite" 动画默认执行一次 infinite表示动画一直执行
android:repeatMode="" 设置动画的重复启动模式 restart表示动画一直从from变化到to
reverse 表示动画从from-to-from-to
使用步骤:
(1)在res文件夹创建anim文件夹
(2)在res/anim/文件夹下创建相应的xml文件
A.淡入淡出:创建根标签为alpha的xml文件
< alpha
xmlns:android="http://schemas.android.com/apk/res/android"
//alpha 通过控制透明度实现动画的效果
//透明度的变化情况 0.0-1.0 0.0完全透明 1.0表示完全不透明
android:fromAlpha="浮点" 设置动画的起始的透明度
android:toAlpha="浮点" 设置动画的结束的透明度
....其他共有属性
>
</ alpha >
B.缩放:创建根标签为 scale 的xml文件
< scale xmlns:android="http://schemas.android.com/apk/res/android"
//scale 缩放 通过尺寸的改变实现动画效果
android:fromXScale="" 表示动画起始x轴的尺寸
android:fromYScale="" 表示动画起始y轴的尺寸
android:toXScale="" 表示动画结束x轴的尺寸
android:toYScale="" 表示动画结束Y轴的尺寸
android:pivotX="" 表示缩放x轴的中心点
android:pivotY="" 表示缩放y轴的中心点
....其他共有属性
>
</ scale >
C.平移:创建根标签为 translate 的xml文件
< translate xmlns:android="http://schemas.android.com/apk/res/android"
//平移 位置改变的动画效果
android:fromXDelta="0" 表示起始和结束x轴的变化
android:toXDelta="300"
android:fromYDelta="0" 表示起始和结束y轴的变化
android:toYDelta="500"
....其他共有属性
>
</ translate >
D.旋转:创建根标签为 rotate 的xml文件
< rotate xmlns:android="http://schemas.android.com/apk/res/android"
// rotate 旋转
android:fromDegrees="旋转的起始角度"
android:toDegrees="旋转的结束角度"
toDegrees-fromDegrees 正数 顺时针 负数 逆时针
android:pivotX="50%"
android:pivotY="50%“
....其他共有属性
// 以x轴和y轴确定旋转中心的坐标
//取值三种情况 直接指定数值 0%-100%表示旋转中心以view自身的xy作为参考 0%p-100%p 表示以view的父布局或者父容器的xy作为参
>
</ rotate >
E.组合:创建根标签为 set 的xml文件,中间可以组合多种动画标签
< set xmlns:android="http://schemas.android.com/apk/res/android"
共有的属性。。。
>
<alpha/rotate/ translate/scale
特有属性....
/>
</ set >
(3)在activity中
ImageView iv= (ImageView) findViewById(R.id.iv)
Animation animation =null;
// loadAnimation(上下文,表示当前加载动画xml文件的资源id)加载动画的函数 animation= AnimationUtils.loadAnimation (MainActivity.this,R.anim.alpha_anim);
//startAnimation()启动动画
iv.startAnimation(animation);

activity之间的跳转动画效果:
Intent intent=new Intent(WellcomActivity.this,MainActivity.class);
startActivity(intent);
WellcomActivity.this.finish();
overridePendingTransition(R.anim.in_action,R.anim.out_action);


在avtivity中动态设置动画效果:
ScaleAnimation scaleAnimation=new ScaleAnimation(0,1,0,1);
//设置显示时间 毫秒
scaleAnimation.setDuration(3000);
//设置最后是否显示最终状态
scaleAnimation.setFillAfter(true);
//设置显示次数
scaleAnimation.setRepeatCount(Animation.INFINITE);
//设置循环显示的模式
scaleAnimation.setRepeatMode(Animation.RESTART);

TranslateAnimation translateAnimation=new TranslateAnimation(-100,0,-100,0);
RotateAnimation rotateAnimation=new RotateAnimation(0,90,0,0);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值