【移动应用开发技术】Android-之动画1_第1页
【移动应用开发技术】Android-之动画1_第2页
【移动应用开发技术】Android-之动画1_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】Android_之动画1

近一周以来一直在搞android动画,被android动画搞的焦头烂额,不过最艰难的时间已经过去,现在写一篇博客,来给自己做一个梳理和总结。

Android3.0以后新增了属性动(propertyanimation),至此Android包含三种动画类型,即补间动画(TweenAnimation),逐帧动画(Drawableanimation),属性动画(Propertyanimation),今天这篇博客着重对属性动画做一个详细阐述。

补间动画(TweenAnimation)补间动画类似于之前学过的Flash动画,设定好初始帧和结束帧以后,中间的值由系统自动进行插值,然后可以形成一种动画效果,补间动画需要用户设定好初始值和结束值,系统自动计算之间值。对于这种动画来说,建议用户使用XML文件配置动画,anim.xml文件应存放于res/anim文件夹下,xml文件必须以<alpha>,

<scale>,

<translate>,

<rotate>或<set>作为根元素。官方文件中提供的xml示例代码:<setandroid:shareInterpolator="false">

<scale

android:interpolator="@android:anim/accelerate_decelerate_interpolator"

android:fromXScale="1.0"

android:toXScale="1.4"

android:fromYScale="1.0"

android:toYScale="0.6"

android:pivotX="50%"

android:pivotY="50%"

android:fillAfter="false"

android:duration="700"/>

<setandroid:interpolator="@android:anim/decelerate_interpolator">

<scale

android:fromXScale="1.4"

android:toXScale="0.0"

android:fromYScale="0.6"

android:toYScale="0.0"

android:pivotX="50%"

android:pivotY="50%"

android:startOffset="700"

android:duration="400"

android:fillBefore="false"/>

<rotate

android:fromDegrees="0"

android:toDegrees="-45"

android:toYScale="0.0"

android:pivotX="50%"

android:pivotY="50%"

android:startOffset="700"

android:duration="400"/>

</set>让动画跑起来也是十分简单的,定义好动画xml文件以后,使用如下代码使用对象和动画的绑定ImageView

spaceshipImage

=

(ImageView)

findViewById(R.id.spaceshipImage);Animation

hyperspaceJumpAnimation

=

AnimationUtils.loadAnimation(this,

动画文件);spaceshipImage.startAnimation(hyperspaceJumpAnimation);

补间动画只是启动空间显示的位置,但是没有移动或者改变空间在布局当中实际文字,例如一个Button在空间中的位置(100,100),X轴方向移动n个单位以后,Button实际位置依然在(100,100)。

2.逐帧动画(Frameanimation)

逐帧动画类似于电影播放的原理,一个图片资源代表一帧,以一定时间间隔进行切换图片资源,形成一种动画效果。一般情况下,逐帧动画也是通过xml文件定义的,下面是官方提供的一个示例代码:<animation-listxmlns:android="/apk/res/android"

android:oneshot="true">

<itemandroid:drawable="@drawable/rocket_thrust1"android:duration="200"/>

<itemandroid:drawable="@drawable/rocket_thrust2"android:duration="200"/>

<itemandroid:drawable="@drawable/rocket_thrust3"android:duration="200"/></animation-list>其中有一个属性是非常重要的,android:oneshot="true",若为true,则代表动画完成以后,停留在最后一帧,反之停留在第一帧。让动画开始也是非常简单的,看官方代码:AnimationDrawablerocketAnimation;publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

ImageViewrocketImage=(ImageView)findViewById(R.id.rocket_p_w_picpath);

rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

rocketAnimation=(AnimationDrawable)rocketImage.getBackground();}publicbooleanonTouchEvent(MotionEventevent){

if(event.getAction()==MotionEvent.ACTION_DOWN){

rocketAnimation.start();

returntrue;

}

returns

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论