android animator 简书,Android动画基础

先上个动画小图

abe7a992a09b

Q:Android 中动画有几类?

A:目前有三种:分别是补间动画、帧动画和属性动画。

tween补间动画

通过指定View的初末状态和变化时间、方式,对View的内容完成一系列的图形变换来实现动画效果。

补间动画在细分可以分为渐变动画与转换动画

渐变动画

转换动画

alpha(AlphaAnimation)

translate(TranslateAnimation)

scale(ScaleAnimation)

rotate(RotetaAnimation)

对于xml中各个效果的属性设定就不在详细描述,放在下面属性动画会提到

最后通过View.startAnimation()来为子类添加动画效果

frame帧动画

AnimationDrawable 控制 animation-list xml布局

xml中内容展示

Java中的代码

imageview.setBackground(R.anim.anim);

AnimationDrawable anims = (AnimationDrawable)imageview.getBackground()

anims.start();

属性动画(Propety Animation)

Duration动画持续时间,默认300ms

Time interpolation 插补器,定义动画的变化率

Repeat count and behavior 重复次数、以及重复模式

Animator set 动画集合,你可以定义一组动画,一起执行或者顺序执行

Frame refresh delay 帧刷新延迟,对于你的动画,多久刷新一次帧,默认为10ms

相关类

ObejctAnimator 动画的执行类

ValueAnimator 动画的执行类

AnimatorSet 用于控制一组动画的执行

TypeEvaluator 类型估值,主要用于设置动画操作属性的值

TimeInterpolator 插补器

ObjectAnimator

ObjectAnimator.ofFloat(this,"rotationX",0.0f,360.0f).setDuration(500).start();

提供了ofInt、ofFloat、ofObject,这几个方法都是设置动画作用的元素、作用的属性、动画开始、结束中间的任意个属性值。

ValueAnimator

ValueAnimator.ofFloat(0,100).setTarget(this).setDuration(1000).start();

监听动画的事件

AnimatorUpdateListener

AnimatorListener

AnimatorListenerAdapter

AnimatorSet

ObjectAnimator anim1 = ObjectAnimator.ofFloat(this,"scaleX",1.0f,2f);

Objectanimator anim2 = ObjectAnimator.ofFloat(this,"scaleY",1.0f,2f);

AnimatorSet animSet = new AnimatorSet();

animSet.setDuration(1000);

animSet.setInterpolator(new LinearInterpolator());

animSet.playTogether(anim1,anim2);

animSet.start();

xml创建属性动画

android:duration="1000"

android:propertyName="scaleX"

android:valueFrom="1.0"

android:valueTo="2.0"

android:valueType="floatType"

/>

AnimatorInflater.loadAnimator(this,R.animator.scalex)

.setTarget(mMv)

.start();

overridePendingTransition activity转场动画效果

Material Design中的Transaction动画

Ripple Effect

MD中在用户触摸屏幕时提供反馈,有助于视觉交流,形成互动。可以通过如下代码设置波纹的背景:

android:background="?android:attr/selectableItemBackground" //默认选项,在视图范围内展示波纹效果

android:backgournd="?android:attr/selecableItemBackgroundBorderless" //可选项,将波纹延伸到视图之外

android:background="@drawable/customRipple" //自定义背景的ripple effect

customRipple.xml

android:color="#c9352a"

>

这里通过几个button的点击效果可以直观的感受下ripples

Circular Reveal

简单翻译来说称之为圆形展现

ViewAnimationUtil.createCircularReveal(View view,int centerX,int centerY,float startRadius,float endRadius).start()

centerX –点击视图的 X轴中心;

centerY -点击视图的 Y轴中心;

view –要显示的视图;

startRadius 动画开始半径

startRadius 动画结束半径

Transitions

Interpolators

enter 决定活动视图如何进入场景

exit 决定活动视图如何退出场景

reenter 决定活动试图退出后如何再度进入场景

shared elements 决定活动间如何共享视图转换

VectorDrawable

Height & Width –矢量图像的实际大小;

Viewport Height & Width –声明描述矢量路径的虚拟画布的大小;

Group name –声明路径所属的组名;

Pivot X & Y –声明群组规模和旋转所使用的中心点;

Path Fill Color –描述矢量路径的填充色;

Path Data –声明用于绘制矢量的矢量路径数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值