android 补间动画set,Android中属性动画和补间动画的区别

属性动画和补间动画的区别是,补间动画只是表面上实现了平移,旋转,渐变,缩放,实际上属性值不变;

属性动画实现平移,旋转,渐变,缩放后,属性值变了

下面就是测试的例子

代码:

package com.atguigu.propertyanimation;

import android.animation.Animator;

import android.animation.AnimatorSet;

import android.animation.ObjectAnimator;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.animation.AlphaAnimation;

import android.view.animation.Animation;

import android.view.animation.AnimationSet;

import android.view.animation.BounceInterpolator;

import android.view.animation.LinearInterpolator;

import android.view.animation.OvershootInterpolator;

import android.view.animation.RotateAnimation;

import android.view.animation.ScaleAnimation;

import android.view.animation.TranslateAnimation;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

/**

* 测试属性动画的基本使用

* 属性动画和补间动画的区别是,补间动画只是表面上实现了平移,旋转,渐变,缩放,实际上属性值不变;

* 属性动画实现平移,旋转,渐变,缩放后,属性值变了

* 下面就是测试的例子

*/

public class MainActivity extends Activity {

private ImageView iv_animation;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

iv_animation = (ImageView) findViewById(R.id.iv_animation);

iv_animation.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(MainActivity.this, "点击了图片", Toast.LENGTH_SHORT).show();

}

});

}

/**

* 补间(视图)动画

* @param v

*/

public void testTweenAnimation(View v) {

TranslateAnimation animation = new TranslateAnimation(0, iv_animation.getWidth(), 0, iv_animation.getHeight());

animation.setDuration(3000);

animation.setFillAfter(true);

iv_animation.startAnimation(animation);

}

private AnimatorSet animatorSet;

/**

* 测试属性动画

*/

public void testPropertyAnimation(View v) {

// x轴上移动

ObjectAnimator animator3 = ObjectAnimator.ofFloat(iv_animation,"translationX",0,iv_animation.getWidth());

// y轴上移动

ObjectAnimator animator4 = ObjectAnimator.ofFloat(iv_animation,"translationY",0,iv_animation.getHeight());

AnimatorSet set = new AnimatorSet();

// 两个动画一起播放

set.playTogether(animator3,animator4);

// 播放时间2秒

set.setDuration(2000);

// 开始播放

set.start();

// //另外一种写法

// iv_animation.animate()

// .translationXBy(iv_animation.getWidth())

// .translationYBy(iv_animation.getWidth())

// .setDuration(2000)

// .setInterpolator(new BounceInterpolator())

// .start();

// ObjectAnimator animator = ObjectAnimator.ofFloat(iv_animation, "translationX", 0,iv_animation.getWidth());

// ObjectAnimator animator2 = ObjectAnimator.ofFloat(iv_animation, "translationY", 0,iv_animation.getHeight());

// AnimatorSet animatorSet = new AnimatorSet();

// animatorSet.setDuration(2000);

// animatorSet.setInterpolator(new BounceInterpolator());

// //两个动画一起播放

// animatorSet.playTogether(animator, animator2);

// //开始播放

// animatorSet.start();

}

public void reset(View v) {

iv_animation.clearAnimation();

}

}布局文件:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:onClick="testTweenAnimation"

android:text="测试补间(视图)动画" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:onClick="testPropertyAnimation"

android:text="测试属性动画" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:onClick="reset"

android:text="重置补间动画" />

android:id="@+id/iv_animation"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@drawable/logo" />

源码下载:

Myjstojava ---- PropertyAnimation

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值