Android - Fragment,View动画,组合动画

aa.setRepeatMode(Animation.REVERSE);

//让iv播放aa动画

iv.startAnimation(aa);

  1. 平移动画

//Animation.RELATIVE_TO_SELF 相对于自己,值要填百分比

//Animation.RELATIVE_TO_PARENT 相对于父控件,值要填百分比

//Animation.ABSOLUTE 绝对坐标,值要填具体值

TranslateAnimation ta = new TranslateAnimation(

Animation.RELATIVE_TO_SELF, //起始x类型

0, //起始x值

Animation.RELATIVE_TO_SELF, //结束x类型

1f, //结束x值

Animation.RELATIVE_TO_SELF, //起始y类型

0, //起始y值

Animation.RELATIVE_TO_SELF, //结束y类型

1f); //结束y值

//动画播放的时间长度

ta.setDuration(2000);

//设置重复播放的次数

ta.setRepeatCount(Animation.INFINITE);

//设置重复播放的模式

ta.setRepeatMode(Animation.REVERSE);

//让iv播放aa动画

iv.startAnimation(ta);

  1. 缩放动画

ScaleAnimation sa = new ScaleAnimation(

0.2f, //x轴起始缩放比

2.0f, //x轴结束缩放比

0.2f, //y轴起始缩放比

2.0f, //y轴结束缩放比

Animation.RELATIVE_TO_SELF, //中心点x类型

0.5f, //中心点x值

Animation.RELATIVE_TO_SELF, //中心点y类型

0.5f //中心点y值

);

//动画播放的时间长度

sa.setDuration(2000);

//设置重复播放的次数

sa.setRepeatCount(Animation.INFINITE);

//设置重复播放的模式

sa.setRepeatMode(Animation.REVERSE);

//让iv播放aa动画

iv.startAnimation(sa);

  1. 旋转动画

RotateAnimation ra = new Rotat 《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》无偿开源 徽信搜索公众号【编程进阶路】 eAnimation(

0,

360,

Animation.RELATIVE_TO_SELF,

0.5f,

Animation.RELATIVE_TO_SELF,

0.5f);

//动画播放的时间长度

ra.setDuration(2000);

//设置重复播放的次数

ra.setRepeatCount(Animation.INFINITE);

//设置重复播放的模式

ra.setRepeatMode(Animation.REVERSE);

//让iv播放aa动画

iv.startAnimation(ra);

10.组合动画的使用方式

AnimationSet set = new AnimationSet(false);

set.addAnimation(ta);

set.addAnimation(sa);

set.addAnimation(ra);

iv.startAnimation(set);

11.使用xml文件描述动画

xml文件放在res/anim文件夹下

<?xml version="1.0" encoding="utf-8"?>

<alpha xmlns:android=“http://schemas.android.com/apk/res/android”

android:fromAlpha=“0.0”

android:toAlpha=“1.0”

android:duration=“2000”

android:repeatCount=“infinite”

android:repeatMode=“reverse” >

使用方式

Animation aa = AnimationUtils.loadAnimation(this, R.anim.alpha_demo);

iv.startAnimation(aa);

12.View动画的特点

View的位置并没有真正的变化,只是改变了渲染的位置

13.属性

生成了get、set方法的成员变量就称为属性

14.属性动画的使用方式

ObjectAnimator oa = ObjectAnimator.ofFloat(iv, “translationY”, new float[]{0,2,4,6,8,10,15,20,25,30,50,80,100,150});

oa.setDuration(2000);

oa.setRepeatCount(ObjectAnimator.INFINITE);

oa.setRepeatMode(ObjectAnimator.RESTART);

oa.start();

15.属性动画的特点

View的位置真正的发生了变化

16.属性动画集合的使用方式

AnimatorSet set = new AnimatorSet();

//顺序播放

set.playSequentially(oa,oa2);

//同时播放

set.playTogether(oa,oa2);

17.使用xml文件描述属性动画

xml文件放在res/animator文件夹下

<?xml version="1.0" encoding="utf-8"?>

<objectAnimator xmlns:android=“http://schemas.android.com/apk/res/android”

android:propertyName=“alpha”

android:duration=“3000”

android:repeatCount=“3”

android:repeatMode=“reverse”

android:valueFrom=“0.0”

android:valueTo=“1.0” >

使用方式

Animator animator = AnimatorInflater.loadAnimator(this, R.animator.alpha);

animator.setTarget(iv);

animator.start();

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值