Android 一般动画animation和属性动画animator
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package com.example.animation;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.animation.TranslateAnimation;import android.widget.ImageView;import android.widget.Toast;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View view){ Toast.makeText(this, "click", Toast.LENGTH_SHORT).show(); } public void move(View view ){ float fromXDelta=0; float toXDelta=0; float fromYDelta=0; float toYDelta=200; TranslateAnimation animation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta); /** * time */ animation.setDuration(1000); animation.setFillAfter(true); ImageView imageView=(ImageView)findViewById(R.id.imageView); imageView.startAnimation(animation); } } |
这是一般动画,再看属性动画
区别:一般动画变换后只是图片移动了,view的位置不变,然而属性动画view随着图片移动。
|
1
2
3
4
5
|
public void move(View view ){ ImageView imageView=(ImageView)findViewById(R.id.imageView); ObjectAnimator.ofFloat(imageView, "translationY", 0f,200f).setDuration(1000).start();} |
多种动画同时进行
|
1
2
3
4
5
6
7
|
public void move(View view ){ ImageView imageView=(ImageView)findViewById(R.id.imageView); ObjectAnimator.ofFloat(imageView, "translationY", 0f,200f).setDuration(1000).start(); ObjectAnimator.ofFloat(imageView, "translationX", 0f,200f).setDuration(1000).start(); ObjectAnimator.ofFloat(imageView, "rotation", 0,360f).setDuration(1000).start();} |
Google提供了一种更节省系统资源的多种动画同时播放
|
1
2
3
4
5
6
7
8
9
|
public void move(View view ){ ImageView imageView=(ImageView)findViewById(R.id.imageView); PropertyValuesHolder p1=PropertyValuesHolder.ofFloat("rotation", 0,360f); PropertyValuesHolder p2=PropertyValuesHolder.ofFloat("translationX", 0f,200f); PropertyValuesHolder p3=PropertyValuesHolder.ofFloat("translationY", 0f,200f); ObjectAnimator.ofPropertyValuesHolder(imageView, p1,p2,p3).setDuration(1000).start();} |
同时Google提供了animatorset,允许多种不同动画按照用户要求播放,如使用set.palyTpgether() set.playSequentially()
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public void move(View view ){ ImageView imageView=(ImageView)findViewById(R.id.imageView); ObjectAnimator animator1=ObjectAnimator.ofFloat(imageView, "rotation", 0,360f); ObjectAnimator animator2=ObjectAnimator.ofFloat(imageView, "translationX", 0,200f); ObjectAnimator animator3=ObjectAnimator.ofFloat(imageView, "translationY", 0,200f); AnimatorSet set=new AnimatorSet(); //set.playTogether(animator1,animator2,animator3); set.playSequentially(animator1,animator2,animator3); set.setDuration(1000); set.start();} |
结伴旅游,一个免费的交友网站:www.jieberu.com
推推族,免费得门票,游景区:www.tuituizu.com
Android 一般动画animation和属性动画animator的更多相关文章
- Android动画效果之初识Property Animation(属性动画)
前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...
- Android动画系列之属性动画
原文首发于微信公众号:jzman-blog,欢迎关注交流! 属性动画相较帧动画和补间动画更强大,帧动画和补间动画只能应用于 View 及其子类,而属性动画可以修改任何对象的属性值,属性值可在指定的一段 ...
- android xml实现animation 4种动画效果
animation有四种动画类型 分别为alpha(透明的渐变).rotate(旋转).scale(尺寸伸缩).translate(移动),二实现的分发有两种,一种是javaCode,另外一种是XML ...
- css动画-animation各个属性详解(转)
CSS3的animation很容易就能实现各种酷炫的动画,虽然看到别人的成果图会觉得很难,但是如果掌握好各种动画属性,做好酷炫吊炸天的动画都不在话下,好,切入正题. 一.动画属性: 动画属性包括:①a ...
- 动画(Animation) 、 高级动画(Core Animation)
1 演示UIImage制作的动画 1.1 问题 UIImage动画是IOS提供的最基本的动画,通常用于制作一些小型的动画,本案例使用UIImage制作一个小狗跑动的动画,如图-1所示: 图-1 1.2 ...
- Android笔记(六十六) android中的动画——XML文件定义属性动画
除了直接在java代码中定义动画之外,还可以使用xml文件定义动画,以便重用. 如果想要使用XML来编写动画,首先要在res目录下面新建一个animator文件夹,所有属性动画的XML文件都应该存放在 ...
- Android动画效果之Property Animation进阶(属性动画)
前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...
- Android动画主要包含补间动画(Tween)View Animation、帧动画(Frame)Drawable Animation、以及属性动画Property Animation
程序运行效果图: Android动画主要包含补间动画(Tween)View Animation.帧动画(Frame)Drawable Animation.以及属性动画Property Animatio ...
- Android(java)学习笔记263:Android下的属性动画(Property Animation)
1. 属性动画(Property Animation)引入: 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系统在一开始的时候就给我们提供了两种实现动画效果的方式,逐帧动画(fra ...
随机推荐
- mybatis-sql执行流程源码分析
1. SqlSessionFactory 与 SqlSession. 通过前面的章节对于mybatis 的介绍及使用,大家都能体会到SqlSession的重要性了吧, 没错,从表面上来看,咱们都是通过 ...
- Python 入门 之 反射
Python 入门 之 反射 1.反射 : (自省) 反射主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省). Python面向对象中的反射:通过字符串的形式操作对象的相关属性.P ...
- Spring的事务传播机制实例 (转)
1,Propagation.REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中.详细解释在代码下方. 实例 员工service @Service public ...
- HTTP协议 django下载安装 url路由分发
今日内容 HTTP协议 MVC和MTV框架模式 django下载安装 django的url路由分发 HTTP协议 http协议 请求信息格式 GET / HTTP/1.1 请求行 Host: 127. ...
- CentOS 7 yum安装LAMP,LNMP并搭建WordPress个人博客网站
本次实验要进行的是在CentOS7.2,内核版本3.10.0-327.el7.x86_64的环境下搭建LAMP和LNMP,并在此之上做一个WordPress博客网站. [root@Shining ~] ...
- Postman之前言
Postman是一款流行的接口api调试/测试工具.几乎可以发送大多数的HTTP请求. 1.依据开发提供的接口文档,对接口进行测试. 2.如果是自己学习,可以网上找一些免费的接口进行学习,或者抓包 - ...
- createTextNode() 方法和createTextNode()方法
<!DOCTYPE html><html><head><meta charset="utf-8"><title>菜鸟教程 ...
- css中的position 的absolute和relative的区别(转)
我们先来看看CSS3 Api中对position属性的相关定义: static:无特殊定位,对象遵循正常文档流.top,right,bottom,left等属性不会被应用. relative:对象遵循 ...
- 浅析HBase:为高效的可扩展大规模分布式系统而生
什么是HBase Apache HBase是运行在Hadoop集群上的数据库.为了实现更好的可扩展性(scalability),HBase放松了对ACID(数据库的原子性,一致性,隔离性和持久性)的要 ...
- resulting in duplicate entry '1' for key 'primary'
现在有一个标签表,里面已经填入了一些数据了,想把主键生成策略改成自增的: ALTER TABLE `tags` CHANGE COLUMN `Id` `Id` INT(11) NOT NULL AUT ...