当前位置: 首页 > news >正文

Android Property Animation属性动画:rotation旋转(2)



Android Property Animation属性动画:rotation旋转(2)

附录的文章1,说明了如何简单的实现一个Android的属性动画Property Animation渐变透明。
本文以Android属性动画的旋转为例,说明如何实现Android属性动画Property Animation的旋转。和附录的文章1为基础,只需要在附录文章1的基础上略加修改,即可实现Property Animation属性动画的旋转。

package zhangphil.anim;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends Activity {

	private TextView text;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		text = (TextView) findViewById(R.id.text);
	}

	// 动画实际执行
	private void startPropertyAnim() {
		// 第二个参数"rotation"表明要执行旋转
		// 0f -> 360f,从旋转360度,也可以是负值,负值即为逆时针旋转,正值是顺时针旋转。
		ObjectAnimator anim = ObjectAnimator.ofFloat(text, "rotation", 0f, 360f);

		// 动画的持续时间,执行多久?
		anim.setDuration(5000);

		// 回调监听
		anim.addUpdateListener(new AnimatorUpdateListener() {

			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				float value = (Float) animation.getAnimatedValue();
				Log.d("zhangphil", value + "");
			}
		});

		// 正式开始启动执行动画
		anim.start();
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == R.id.action_anim) {

			// 此处正式启动属性动画
			startPropertyAnim();

			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}


附录文章:
1,《Android Property Animation属性动画初识:透明渐变(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/50484224

相关文章:

  • linux上很方便的上传下载文件工具rz和sz使用介绍
  • 2016.1.13 随笔
  • JMeter基础之一 一个简单的性能测试
  • [Java开发之路](14)反射机制
  • MDEV Primer
  • 闹心的变量
  • [转载]项目风险管理七种武器-碧玉刀
  • 会声会影简易相册制作教程
  • Spark学习之基于MLlib的机器学习
  • zabbix在centos6下的编译安装
  • C语言 百炼成钢1
  • 【Linux】环境变量设置
  • Apache安装教程
  • 数众数
  • Struts的属性驱动和模型驱动
  • [笔记] php常见简单功能及函数
  • fetch 从初识到应用
  • JavaScript-Array类型
  • js作用域和this的理解
  • Mithril.js 入门介绍
  • Python语法速览与机器学习开发环境搭建
  • Vue ES6 Jade Scss Webpack Gulp
  • vuex 笔记整理
  • webgl (原生)基础入门指南【一】
  • webpack项目中使用grunt监听文件变动自动打包编译
  • windows下mongoDB的环境配置
  • zookeeper系列(七)实战分布式命名服务
  • 持续集成与持续部署宝典Part 2:创建持续集成流水线
  • 从零开始学习部署
  • 二维平面内的碰撞检测【一】
  • 解决jsp引用其他项目时出现的 cannot be resolved to a type错误
  • 线性表及其算法(java实现)
  • 学习Vue.js的五个小例子
  • Java性能优化之JVM GC(垃圾回收机制)
  • #Linux杂记--将Python3的源码编译为.so文件方法与Linux环境下的交叉编译方法
  • (2)(2.10) LTM telemetry
  • (附源码)spring boot网络空间安全实验教学示范中心网站 毕业设计 111454
  • (中等) HDU 4370 0 or 1,建模+Dijkstra。
  • .NET Core WebAPI中封装Swagger配置
  • .net core 调用c dll_用C++生成一个简单的DLL文件VS2008
  • .net core 控制台应用程序读取配置文件app.config
  • .net core 连接数据库,通过数据库生成Modell
  • .net framework 4.0中如何 输出 form 的name属性。
  • .Net Memory Profiler的使用举例
  • .Net 代码性能 - (1)
  • .net 前台table如何加一列下拉框_如何用Word编辑参考文献
  • .NET 中小心嵌套等待的 Task,它可能会耗尽你线程池的现有资源,出现类似死锁的情况
  • .Net8 Blazor 尝鲜
  • .NET命名规范和开发约定
  • .NET与java的MVC模式(2):struts2核心工作流程与原理
  • .net专家(张羿专栏)
  • ?.的用法
  • @RequestMapping 的作用是什么?
  • [ CTF ] WriteUp- 2022年第三届“网鼎杯”网络安全大赛(白虎组)
  • [.net 面向对象程序设计进阶] (19) 异步(Asynchronous) 使用异步创建快速响应和可伸缩性的应用程序...