Android属性动画-简单实例
1.ValueAnimator
//在2000毫秒内,将值从0过渡到1的动画
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setDuration(2000);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float currentValue = (float) valueAnimator.getAnimatedValue();
Log.e("tag", "currentValue="+currentValue);
String textStr = ((int) (currentValue * 60)) + "";
text1_tv.setText(textStr);
}
});
anim.start();
2.ObjectAnimator
//将TextView从常规变换成全透明,再从全透明变换成常规
ObjectAnimator anim1 = ObjectAnimator.ofFloat(text2_tv, "alpha", 1f, 0f, 1f);
anim1.setDuration(3000);
anim1.start();
//将TextView进行一次360度的旋转
ObjectAnimator anim2 = ObjectAnimator.ofFloat(text2_tv, "rotation", 0f, 360f);
anim2.setDuration(3000);
anim2.start();
//将TextView先向左移出屏幕,然后再移动回来
float curTranslationX = text2_tv.getTranslationX();
ObjectAnimator anim3 = ObjectAnimator.ofFloat(text2_tv, "translationX", curTranslationX, -500f, curTranslationX);
anim3.setDuration(3000);
anim3.start();
//将TextView在垂直方向上放大3倍再还原
ObjectAnimator anim4 = ObjectAnimator.ofFloat(text2_tv, "scaleY", 1f, 3f, 1f);
anim4.setDuration(5000);
anim4.start();
3.组合动画
//让TextView先从屏幕外移动进屏幕,然后开始旋转360度,旋转的同时进行淡入淡出操作
ObjectAnimator moveIn = ObjectAnimator.ofFloat(text3_tv, "translationX", -500f, 0f);
ObjectAnimator rotate = ObjectAnimator.ofFloat(text3_tv, "rotation", 0f, 360f);
ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(text3_tv, "alpha", 1f, 0f, 1f);
AnimatorSet animSet = new AnimatorSet();
animSet.play(rotate).with(fadeInOut).after(moveIn);
animSet.setDuration(5000);
animSet.start();
Android属性动画-简单实例的更多相关文章
- Android属性动画简单剖析
运行效果图: 先看布局文件吧,activity_main.xml: <?xml version="1.0" encoding="utf-8"?> & ...
- Android属性动画完全解析(下)
转载:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中我们学习了 ...
- Android属性动画完全解析(上),初识属性动画的基本用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系 ...
- Android属性动画完全解析(中)
转载:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是 ...
- Android属性动画完全解析(上)
Android属性动画完全解析(上) 转载:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷 ...
- Android 属性动画 源码解析 深入了解其内部实现
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42056859,本文出自:[张鸿洋的博客] 我参加了博客之星评选,如果你喜欢我的博 ...
- Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中 ...
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...
- Android属性动画-基本用法
在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系统在一开始的时候就给我们提供了两种实现动画效果的方式,逐帧动画(frame-by-frame animation)和补间动画(twe ...
随机推荐
- shortcuts for contructor 创建对象捷径
- 在windows系统和kali中通过sqlmap注入
第1章 在windows系统中通过sqlmap注入 1.1 环境搭建 Sqlmap是目前功能最强大,使用最为广泛的注入类工具,是一个开源软件,被集成于kaliLinux, 由于sqlmap是基于Pyt ...
- django-用户浏览记录添加及商品详情页
视图函数views.py # /goods/商品id class DetailView(View): '''详情页''' def get(self, request, goods_id): '''显示 ...
- Django API接口FK ManyTo Many 模板
Url from django.contrib import admin from django.urls import path, re_path from django.urls import i ...
- 如何把上传图片时候的文件对象转换为图片的url !
getObjectURL(file) { var url = null; if (window.createObjectURL != undefined) { url = window.createO ...
- WinDbg 图形界面功能(三)
1.4.调试菜单 调试相关操作的功能菜单在这个下面,比如单步执行等. Go 单击Go调试菜单恢复 (或开始) 在目标上的执行. 此执行将继续,直到抵达某个断点. 异常或事件发生时,该过程结束或调试器将 ...
- 开源项目 08 IOC Autofac
using Autofac; using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- CF 768B
CF 768B题意:In each operation Sam must remove any element x, such that x>1, from the list and inser ...
- 洛谷 P3371 【模板】单源最短路径(弱化版) 题解
P3371 [模板]单源最短路径(弱化版) 题目背景 本题测试数据为随机数据,在考试中可能会出现构造数据让SPFA不通过,如有需要请移步 P4779. 题目描述 如题,给出一个有向图,请输出从某一点出 ...
- 解决IE报错:Locale 'chinese' is not well-formed,或RangeError: 区域设置“chinese”的格式不正确的问题
接之前的此博客问题处理:js处理时间时区问题 由于 toLocaleString():据本地时间格式,把 Date 对象转换为字符串.总是会带有上午/下午,所以我加了参数:new Date('2019 ...