安卓开发动画效果

本文介绍了在Android开发中如何实现炫丽的动画效果,重点探讨了四大动画类型:淡入淡出、缩放、旋转和移动,并提供了XML布局文件的示例代码,帮助开发者创建吸引人的用户界面。

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


动画在很多应用中都存在,尤其是游戏类的应用,在做android开发时,UI往往是最费时间,但一个效果炫丽的UI也往往是一款应用吸引人的地方。而动画效果可以做出很多炫丽的效果,下面列举下android的动画开发——Animation的动画效果。

动画类型

Android的animation由四种类型组成

XML中 

alpha渐变透明度动画效果
scale渐变尺寸伸缩动画效果
translate画面转换位置移动动画效果
rotate画面转移旋转动画效果
JavaCode中
AlphaAnimation渐变透明度动画效果
ScaleAnimation渐变尺寸伸缩动画效果
TranslateAnimation画面转换位置移动动画效果
RotateAnimation画面转移旋转动画效果
Android动画模式

Animation主要有两种动画模式:
一种是tweened animation(渐变动画)
XML中JavaCode
alphaAlphaAnimation
scaleScaleAnimation


一种是frame by frame(画面转换动画)
XML中JavaCode
translateTranslateAnimation
rotateRotateAnimation
在XML文件中定义动画

① 打开Eclipse,新建Android工程
② 在res目录中新建anim文件夹
③ 在anim目录中新建一个myanim.xml(注意文件名小写)

④ 加入XML的动画代码



共同的布局文件

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  7.     android:layout_width="fill_parent"  
  8.     android:layout_height="wrap_content"  
  9.     android:orientation="horizontal">  
  10.   
  11.     <Button  
  12.         android:id="@+id/Alpha"  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="淡入淡出" />  
  16.     <Button  
  17.         android:id="@+id/scale"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:text="缩放效果" />  
  21.     <Button  
  22.         android:id="@+id/rotate"  
  23.         android:layout_width="wrap_content"  
  24.         android:layout_height="wrap_content"  
  25.         android:text="旋转效果" />  
  26.     <Button  
  27.         android:id="@+id/translate"  
  28.         android:layout_width="wrap_content"  
  29.         android:layout_height="wrap_content"  
  30.         android:text="移动效果" />  
  31.     </LinearLayout>  
  32.     <ImageView  
  33.         android:id="@+id/image"  
  34.         android:layout_width="wrap_content"  
  35.         android:layout_height="wrap_content"  
  36.         android:src="@drawable/a" />  
  37.       
  38.   
  39. </LinearLayout>  


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值