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. java解析json字符串详解(两种方法)

    一.使用JSONObject来解析JSON数据官方提供的,所以不需要导入第三方jar包:直接上代码,如下 private void parseJSONWithJSONObject(String Jso ...

  2. PHP使用CURL抓取页面

    cURL的基本原理 curl是利用URL语法在命令行方式下工作的开源文件传输工具,他能够从互联网上获得各种各样的网络资源.简单来说,curl就是抓取页面的升级版. <?php //1.初始化,创 ...

  3. 基于FCN的图像语义分割

    语义图像分割的目标在于标记图片中每一个像素,并将每一个像素与其表示的类别对应起来.因为会预测图像中的每一个像素,所以一般将这样的任务称为密集预测.(相对地,实例分割模型是另一种不同的模型,该模型可以区 ...

  4. Feign声明式服务调用

    Feign是一种声明式.模板化的HTTP客户端(仅在Application Client中使用).声明式调用是指,就像调用本地方法一样调用远程方法,无需感知操作远程http请求. Spring Clo ...

  5. P3488 [POI2009]LYZ-Ice Skates

    传送门 这一题基础是二分图匹配,并且要知道一个 $Hall$ 定理:对于二分图能完全匹配的充要条件是,设点数少的那边为左边,点数为 $n$,对于 $k \in [1,n]$ ,左边任意 $k$ 个点, ...

  6. Jave Web使用的设计模型

    Jave Web使用的设计模型 Mybatis 源码解读-设计模式总结 ImportNew 5月15日 (给ImportNew加星标,提高Java技能) 作者:crazyant www.crazyan ...

  7. java中super总结

    1:super 可以在子类调用父类中的成员变量(包括static修饰的变量)和方法(包括static修饰的方法) 2:super 可以调用父类的构造方法 super(参数列表),在没有定义时,并且没有 ...

  8. 【原创】运维基础之Nginx(3)location和rewrite

    nginx location =:精确匹配(必须全部相等) ~:大小写敏感,正则匹配 ~*:忽略大小写,正则匹配 ^~:只需匹配uri部分,精确匹配 @:内部服务跳转,精确匹配 优先级: Exact ...

  9. JavaScript制作九九乘法表

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. 多线程编程-- part5.1 互斥锁ReentrantLock

    ReentrantLock简介 Reentrantlock是一个可重入的互斥锁,又被称为独占锁. Reentrantlock:分为公平锁和非公平锁,它们的区别体现在获取锁的机制上是否公平.“锁”是为了 ...