Animation和Animator的简单区别
来源:互联网 发布:c语言《》 编辑:程序博客网 时间:2024/05/17 01:58
在前几篇博客中讲述了如何使用视图动画和如何使用插值器以及自定义自己的插值器,在本篇博客中,我将向你讲述animator和animation的简单区别。属性动画与视图动画相比,存在哪些有点呢,首先视图动画能做的属性动画都可以做,而且可以做的的更好。在视图动画中,如果对一个button做移动动画,那么button的点击事件的有效点击区域并不会随着button的移动而发生改变,但是属性动画不一样,如果使用属性动画对button做移动动画,事件的点击区域会随着移动不断发生改变的。
详细情况还是看一下效果图吧:
可以很明显的看出,使用animator的时候,响应点击事件的有效区域也会发生改变。
现在看一下代码:
主布局文件:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.animatorandanimation.MainActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="showToast" android:src="@mipmap/ic_launcher" android:id="@+id/iv"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:orientation="vertical"> <Button android:onClick="startAnimation" android:text="@string/app_name" android:layout_width="match_parent" android:layout_height="wrap_content"/> <Button android:onClick="startAnimator" android:text="@string/app_name" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout></RelativeLayout>
animator文件:
<?xml version="1.0" encoding="utf-8"?><objectAnimator xmlns:android="http://schemas.android.com/apk/res/android" android:valueTo="200dp" android:duration="5000" android:propertyName="translationX" android:valueFrom="0" android:valueType="floatType"></objectAnimator>
animator代表的属性动画,每个动画只能改变一个属性值,如果需要改变多个可以考虑使用动画集。
animation动画:
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="400" android:toYDelta="400" android:duration="5000" android:fillAfter="true"></translate>
Java文件:
package com.example.animatorandanimation;import android.animation.AnimatorInflater;import android.animation.ObjectAnimator;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.view.animation.AnimationUtils;import android.view.animation.TranslateAnimation;import android.widget.ImageView;import android.widget.Toast;public class MainActivity extends AppCompatActivity { private ImageView iv; private TranslateAnimation translateAnimation; private ObjectAnimator objectAnimator; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv); translateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(MainActivity.this,R.anim.translation); objectAnimator = (ObjectAnimator) AnimatorInflater.loadAnimator(MainActivity.this,R.animator.translation); } public void startAnimation(View view){ iv.startAnimation(translateAnimation); } public void startAnimator(View view){ iv.clearAnimation(); objectAnimator.setTarget(iv); objectAnimator.start(); } public void showToast(View view){ Toast.makeText(MainActivity.this,"you click the imageView",Toast.LENGTH_SHORT).show(); }}
代码都很简单,没有什么值得特别讲解的地方,在使用animation和animator的时候,你可以体会一下,这两种动画的思路给人的感觉完全不一样,animation给人一样,View在控制动画的感觉,而animator则刚好相反,它给人一种,动画本身就是存放在那,是使用动画来控制目标对象的。反正我是这么感觉的,有兴趣的朋友可以体会一下。好了,关于视图动画和属性动画的差别就说到这吧,关键是我对这个知道的也不是很多,以后了解了更多的东西再补充吧!!
这是我的微信公众号,如果可以的话,希望您可以帮忙关注一下,这将是对我最大的鼓励了,谢谢!!
代码地址:
https://github.com/zhuyuqiang2017/Animation
- Animation和Animator的简单区别
- android之animator 和animation 的区别
- animation和animator
- Animation遇到的小坑及简单的Animator使用
- Object Animator和Tween Animation
- Android中关于Animation和Animator动画的知识点总结
- 【Unity3d】Animator和Animation组件使用注意事项
- 【Unity3d】Animator和Animation组件使用注意事项
- Android中AnimationDrawable,Animator和Animation
- Unity Animator采样和Animation采样
- 浅谈android Animation Animator 的实现原理
- Animator与Animation之间的互转
- Android菜鸟的我对于view animator 和 property animation异同的理解
- uinity Animator 和Animation的正播,捯播,暂停动画实现方法(测试)
- [cnblogs镜像]Unity中 Animator 与Animation 区别
- transition和animation的区别
- Android 一般动画animation和属性动画animator
- Unity3D游戏开发之详解 Animation类和Animator类
- 118. Pascal's Triangle
- The requested resource is not available.http404
- Linux信号量(进程)
- java设计模之OO原则小结
- Unity Editor 基础篇(五):Gizmos
- Animation和Animator的简单区别
- Linux下的软件的几种分类
- java基本知识-面试题简答
- 51nod独木舟问题
- 数据库设计三原则
- 2017.3.25校内赛(balance)(hill)(draw)(knight)
- react-native之每隔一秒刷新页面
- 【设计模式】单例模式
- 山寨版tftp服务器