android 帧动画监听,Android 动画(View动画,帧动画,属性动画)详细介绍

本文详细介绍了Android中的三种动画:View动画、帧动画和属性动画。View动画包括平移、缩放、旋转和透明度变换;帧动画通过连续切换图片实现;属性动画能真实改变对象属性,支持点击位置变化。同时,文章讨论了自定义动画、动画监听器和插值器的使用,以及如何为ViewGroup和Activity设置动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0. 前言

Android动画是面试的时候经常被问到的话题。我们都知道Android动画分为三类:View动画、帧动画和属性动画。

先对这三种动画做一个概述:

View动画是一种渐进式动画,通过图像的平移、缩放、旋转和透明度等各种渐进式变换完成动画效果。

帧动画是通过不停的切换图片实现动画效果。

属性动画是不停的改变对象的属性来实现动画效果。本文原创,转载请注明出处:

http://blog.csdn.net/seu_calvin/article/details/52724655

1.  View动画

1.1  系统提供的四种View动画(补间动画)

View动画可以在res/anim/name.xml文件里进行配置,四种View动画的渐变式变换分别对应、、、四个标签,动画集合可以使用标签。xml的各个动画属性比较简单,这里就不再贴实例代码了。只需要注意如何应用配置好的xml文件来启动动画即可:

view.startAnimation(AnimationUtils.loadAnimation(this,R.anim.myanimation));

这些当然也可以在Java代码里进行配置,也比较简单,这里写了一个示例代码:

splash = (RelativeLayout)findViewById(R.id.splash);

//旋转动画

RotateAnimation rotateAnimation = new RotateAnimation(0,360,

Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);

rotateAnimation.setDuration(2000);

rotateAnimation.setFillAfter(true);

//缩放动画

ScaleAnimation scaleAnimation = new ScaleAnimation(0,1,0,1,

Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);

scaleAnimation.setDuration(2000);

scaleAnimation.setFillAfter(true);

//渐变动画

AlphaAnimation alphaAnimation = new AlphaAnimation(0.2f,1.0f);

alphaAnimation.setDuration(2000);

alphaAnimation.setFillAfter(true);

//平移动画

TranslateAnimation translateAnimation = newTranslateAnimation (0,0,100,100);

translateAnimation.setDuration(2000);

translateAnimation.setFillAfter(true);

//动画集合

AnimationSet animationSet = new AnimationSet(true);

animationSet.addAnimation(rotateAnimation);

animationSet.addAnimation(scaleAnimation);

animationSet.addAnimati

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值