RotateAnimation旋转动画Demo
2016-01-12 15:42
274 查看
一、在java中实现动画:
二、在ra.xml中实现动画:
ra.xml:
package com.jikexueyuan.rotateanimation; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.RotateAnimation; public class MainActivity extends Activity { private RotateAnimation ra; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ra = new RotateAnimation( 0 //fromDegrees起始角度 , 360 //toDegrees旋转角度 , Animation.RELATIVE_TO_SELF, 0.5f,//pivotXType 旋转中心的X轴 //RELATIVE_TO_SELF:相对自身 Animation.RELATIVE_TO_SELF, 0.5f//pivotXValue 旋转中心的Y轴 ); ra.setDuration(1000); findViewById(R.id.btnRotateMe).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { arg0.startAnimation(ra); } }); } }
二、在ra.xml中实现动画:
package com.jikexueyuan.rotateanimation; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.AnimationUtils; import android.view.animation.RotateAnimation; public class MainActivity extends Activity { private RotateAnimation ra; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.btnRotateMe).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { arg0.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.ra)); } }); } }
ra.xml:
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:duration="1000" android:pivotX="50%" android:pivotY="50%" > </rotate>
相关文章推荐
- android的事件分发相关
- Datatable 添加新列并赋值
- 浅谈Java Final关键字
- 封装的viewholder和adapter
- [No00007F]2016-面经[下] 英文简历写作技巧
- 值得推荐的C/C++框架和库
- C编译器编译结构体时的对齐原则
- 笨办法学Python学习笔记 练习16
- C语言头文件的作用
- 解决Animation 添加AnimationClip 无效的问题
- HDU2061Treasure the new start, freshmen!
- http://www.cnblogs.com/holyknight-zld/archive/2012/08/09/wcf_uploadpic.html
- Kafka 之 入门
- EntityFramework
- js调用父框架函数与弹窗调用父页面函数的方法
- 多尺度竞争卷积
- Linux shell下的颜色含义
- 简单实用ssm+json+ajax三级联动
- neutron 基本原理
- linux :安装中文输入法