Android动画(Animations)
2016-06-24 15:12
441 查看
Android的animation
动画类型
Android的animation由四种类型组成
XML中
Java代码中
1、main.xml
2、.java文件
动画类型
Android的animation由四种类型组成
XML中
alpha | 渐变透明度动画效果 |
scale | 渐变尺寸伸缩动画效果 |
translate | 画面转换位置移动动画效果 |
rotate | 画面转移旋转动画效果 |
AlphaAnimation | 渐变透明度动画效果 |
ScaleAnimation | 渐变尺寸伸缩动画效果 |
TranslateAnimation | 画面转换位置移动动画效果 |
RotateAnimation | 画面转移旋转动画效果 |
<?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 android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/rotateButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="旋转" /> <Button android:id="@+id/scaleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="缩放" /> <Button android:id="@+id/alphaButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="淡入淡出" /> <Button android:id="@+id/translateButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="移动" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/an" /> </LinearLayout> </LinearLayout>
2、.java文件
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.ImageView; public class Animation1Activity extends Activity{ private Button rotateButton = null; private Button scaleButton = null; private Button alphaButton = null; private Button translateButton = null; private ImageView mImageView = null; private Animation Alpha; private Animation Scale; private Animation Translate; private AnimationRotate; @Override public void onCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); rotateButton =(Button)findViewById(R.id.rotateButton); scaleButton =(Button)findViewById(R.id.scaleButton); alphaButton =(Button)findViewById(R.id.alphaButton); translateButton =(Button)findViewById(R.id.translateButton); mImageView = (ImageView)findViewById(R.id.image); rotateButton.setOnClickListener(newRotateButtonListener()); scaleButton.setOnClickListener(newScaleButtonListener()); alphaButton.setOnClickListener(newAlphaButtonListener()); translateButton.setOnClickListener( new TranslateButtonListener()); } class AlphaButtonListener implementsOnClickListener{ public void onClick(Viewv) { Alpha=animationUtils.loadAnimation(this,R.anim.alpha_action); mImageView.startAnimation(Alpha); } } class RotateButtonListener implementsOnClickListener{ public void onClick(Viewv) { Rotate = AnimationUtils.loadAnimation(this,R.anim.rotate_action); mImageView.startAnimation(Rotate); } class ScaleButtonListener implementsOnClickListener{ public void onClick(Viewv) { Scale =AnimationUtils.loadAnimation(this,R.anim.scale_action); mImageView.startAnimation(Scale); } class TranslateButtonListener implementsOnClickListener{ public void onClick(Viewv) { Translate =AnimationUtils.loadAnimation(this,R.anim.translate_action); mImageView.startAnimation(Translate); } } }
1: alpha_action.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="3000" /> </set> 2:rotate_action.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="0" android:toDegrees="+350" android:pivotX="50%" android:pivotY="50%" android:duration="3000"/> </set> 3: scale_action.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.4" android:fromYScale="0.0" android:toYScale="1.4" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="700"/> </set> 4: translate_action.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="30" android:toXDelta="-80" android:fromYDelta="30" android:toYDelta="300" android:duration="2000"/> </set>
下载地址 :http://download.csdn.net/detail/dickyqie/9558580
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories