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的更多相关文章

  1. Android动画效果之初识Property Animation(属性动画)

    前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...

  2. Android动画系列之属性动画

    原文首发于微信公众号:jzman-blog,欢迎关注交流! 属性动画相较帧动画和补间动画更强大,帧动画和补间动画只能应用于 View 及其子类,而属性动画可以修改任何对象的属性值,属性值可在指定的一段 ...

  3. android xml实现animation 4种动画效果

    animation有四种动画类型 分别为alpha(透明的渐变).rotate(旋转).scale(尺寸伸缩).translate(移动),二实现的分发有两种,一种是javaCode,另外一种是XML ...

  4. css动画-animation各个属性详解(转)

    CSS3的animation很容易就能实现各种酷炫的动画,虽然看到别人的成果图会觉得很难,但是如果掌握好各种动画属性,做好酷炫吊炸天的动画都不在话下,好,切入正题. 一.动画属性: 动画属性包括:①a ...

  5. 动画(Animation) 、 高级动画(Core Animation)

    1 演示UIImage制作的动画 1.1 问题 UIImage动画是IOS提供的最基本的动画,通常用于制作一些小型的动画,本案例使用UIImage制作一个小狗跑动的动画,如图-1所示: 图-1 1.2 ...

  6. Android笔记(六十六) android中的动画——XML文件定义属性动画

    除了直接在java代码中定义动画之外,还可以使用xml文件定义动画,以便重用. 如果想要使用XML来编写动画,首先要在res目录下面新建一个animator文件夹,所有属性动画的XML文件都应该存放在 ...

  7. Android动画效果之Property Animation进阶(属性动画)

    前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...

  8. Android动画主要包含补间动画(Tween)View Animation、帧动画(Frame)Drawable Animation、以及属性动画Property Animation

    程序运行效果图: Android动画主要包含补间动画(Tween)View Animation.帧动画(Frame)Drawable Animation.以及属性动画Property Animatio ...

  9. Android(java)学习笔记263:Android下的属性动画(Property Animation)

    1. 属性动画(Property Animation)引入: 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系统在一开始的时候就给我们提供了两种实现动画效果的方式,逐帧动画(fra ...

随机推荐

  1. 爬取百度贴吧前1000页内容(requests库面向对象思想实现)

    此程序以李毅吧为例子,以面向对象的设计思想实现爬取保存网页数据,暂时并未用到并发处理,以后有机会的话会加以改善 首先去百度贴吧分析贴吧地址栏中url后的参数,找到分页对应的参数pn,贴吧名字对应的参数 ...

  2. java web实现同一账号在不同浏览器不能同时登录

    网上看了很多方法,个人也看了,自己也总结了几个比较常用的: 前提都是用session监听器,对session的创建与销毁进行监听 一.在用户登录时保存该用户的状态有这几种保存方式: 1.保存到内存中( ...

  3. PyTorch安装问题解决

    现在caffe2被合并到了PyTorch中 git clone https://github.com/pytorch/pytorch pip install -r requirements.txtsu ...

  4. 使用CLI 3 创建发布Web Components

    本文翻译自:codementor 翻译不当之处,欢迎指正交流 Web Components是web平台的未来吗?关于这一问题支持和反对的观点有很多.事实上浏览器对Web Components的支持正在 ...

  5. 24、Nginx缓存web服务

    通常情况下缓存是用来减少后端压力, 将压力尽可能的往前推, 减少后端压力,提高网站并发延时 1.缓存常见类型 服务端缓存 代理缓存, 获取服务端内容进行缓存 客户端浏览器缓存 Nginx代理缓存原理 ...

  6. date( ) 日期函数

    date('Y-m-dT2:00')    实际时间为14:00 date('Y-m-d 2:00')     实际时间为2:00 扩展:每天的时间戳秒数为 86400

  7. kubernetes创建资源的两种方式

    一.创建方式分类: 命令 vs 配置文件 Kubernetes 支持两种方式创建资源: 1.用 kubectl 命令行的方式直接创建,比如: kubectl run httpd-app --image ...

  8. dead relu and Tensorboard

    https://medium.com/analytics-vidhya/is-relu-dead-27943b50102 1.使用relu作为激活函数时,因其在输入小于0时,输出为0,所以可能会造成d ...

  9. Hibernate的缓存(收集)

    (1)缓存就是把以前从数据库中查询出来和使用过的对象保存在内存中(一个数据结构中),这个数据结构通常是或类似Hashmap,当以后要使用某个对象 时,先查询缓存中是否有这个对象,如果有则使用缓存中的对 ...

  10. OCP协议_电信特殊协议

    OCP(Online Charging Protocol)协议——在线计费协议(也称为AAA协议),是中国电信(文中以中国电信为主)充分研究国内外在线计费协议,基于中国电信自己在线计费的需求,参考3G ...