Android中两种使用Animation的方法
来源:互联网 发布:99宿舍下载 软件 编辑:程序博客网 时间:2024/05/18 03:38
在Android中,分别可以在xml中定义Animation,也可以在程序代码中定义,下面的小例子是利用RotateAnimation简单展示一下两种方法的用法,对于其他动画,如ScaleAnimation,AlphaAnimation,原理是一样的。
方法一:在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="+360"
- android:duration="3000" />
- <!-- rotate 旋转动画效果
- 属性:interpolator 指定一个动画的插入器,用来控制动画的速度变化
- fromDegrees 属性为动画起始时物件的角度
- toDegrees 属性为动画结束时物件旋转的角度,+代表顺时针
- duration 属性为动画持续时间,以毫秒为单位
- -->
- </set>
使用动画的Java代码,程序的效果是点击按钮,TextView旋转一周:
- package com.ray.animation;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.Button;
- import android.widget.TextView;
- public class TestAnimation extends Activity implements OnClickListener{
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button btn = (Button)findViewById(R.id.Button01);
- btn.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- Animation anim = AnimationUtils.loadAnimation(this, R.anim.my_rotate_action);
- findViewById(R.id.TextView01).startAnimation(anim);
- }
- }
方法二:直接在代码中定义动画(效果跟方法一类似):
- package com.ray.animation;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.AccelerateDecelerateInterpolator;
- import android.view.animation.Animation;
- import android.view.animation.RotateAnimation;
- import android.widget.Button;
- public class TestAnimation extends Activity implements OnClickListener{
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button btn = (Button)findViewById(R.id.Button);
- btn.setOnClickListener(this);
- }
- public void onClick(View v) {
- Animation anim = null;
- anim = new RotateAnimation(0.0f,+360.0f);
- anim.setInterpolator(new AccelerateDecelerateInterpolator());
- anim.setDuration(3000);
- findViewById(R.id.TextView01).startAnimation(anim);
- }
- }
原文:http://rayleung.javaeye.com/blog/413842
- Android中两种使用Animation的方法
- Android中两种使用Animation的方法
- Android中两种使用Animation的方法
- Android中两种Animation的方法
- Android中使用animation的方法
- Android中使用animation的方法
- Android中使用animation的方法
- android Animation的使用
- Android Animation ------ ViewFlipper的使用
- android中Animation的使用!
- android中Animation的使用!
- Android—Animation的使用
- android animation的简单使用
- Android Animation的使用记录
- Android Animation Tween动画效果的使用
- Android Animation Tween动画效果的使用
- android 中关于animation的正确使用
- android简易时钟(animation的使用)
- WinCE中非模态对话框不能关闭的问题
- 上班族时间管理及150%原则
- about yum
- OpenIL(DevIL)
- 有一种爱叫"守口如瓶"
- Android中两种使用Animation的方法
- (转)算法总结系列之一:堆排序(Heap Sort)
- linux socket 优化
- C++中的虚函数
- zt(如何让工作富有创造性)
- 添加打印机提示打印后台程序服务没有运行的解决方法
- MTU MSS
- error C2593: “operator +=”不明确
- C++ vptr vtbl (C++虚表指针,虚函数表,虚函数的实现)很多人都喜欢问这个,写下吧。