动画在很多应用中都存在,尤其是游戏类的应用,在做android开发时,UI往往是最费时间,但一个效果炫丽的UI也往往是一款应用吸引人的地方。而动画效果可以做出很多炫丽的效果,下面列举下android的动画开发——Animation的动画效果。
动画类型
Android的animation由四种类型组成
XML中
alpha | 渐变透明度动画效果 |
scale | 渐变尺寸伸缩动画效果 |
translate | 画面转换位置移动动画效果 |
rotate | 画面转移旋转动画效果 |
AlphaAnimation | 渐变透明度动画效果 |
ScaleAnimation | 渐变尺寸伸缩动画效果 |
TranslateAnimation | 画面转换位置移动动画效果 |
RotateAnimation | 画面转移旋转动画效果 |
Animation主要有两种动画模式:
一种是tweened animation(渐变动画)
XML中 | JavaCode |
alpha | AlphaAnimation |
scale | ScaleAnimation |
一种是frame by frame(画面转换动画)
XML中 | JavaCode |
translate | TranslateAnimation |
rotate | RotateAnimation |
① 打开Eclipse,新建Android工程
② 在res目录中新建anim文件夹
③ 在anim目录中新建一个myanim.xml(注意文件名小写)
④ 加入XML的动画代码
共同的布局文件
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Button
- android:id="@+id/Alpha"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="淡入淡出" />
- <Button
- android:id="@+id/scale"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="缩放效果" />
- <Button
- android:id="@+id/rotate"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="旋转效果" />
- <Button
- android:id="@+id/translate"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="移动效果" />
- </LinearLayout>
- <ImageView
- android:id="@+id/image"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/a" />
- </LinearLayout>