Android中属性动画和补间动画的区别
来源:互联网 发布:大数据信息贩卖 编辑:程序博客网 时间:2024/04/29 09:41
属性动画和补间动画的区别是,补间动画只是表面上实现了平移,旋转,渐变,缩放,实际上属性值不变;
属性动画实现平移,旋转,渐变,缩放后,属性值变了
Myjstojava ---- PropertyAnimation
属性动画实现平移,旋转,渐变,缩放后,属性值变了
下面就是测试的例子
代码:
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(); }}布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="testTweenAnimation" android:text="测试补间(视图)动画" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="testPropertyAnimation" android:text="测试属性动画" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="reset" android:text="重置补间动画" /> <ImageView android:id="@+id/iv_animation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/logo" /></LinearLayout>源码下载:
Myjstojava ---- PropertyAnimation
http://download.csdn.net/download/zhaihaohao1/10020298
阅读全文
0 0
- Android中属性动画和补间动画的区别
- Android中属性动画和补间动画的区别
- Android中属性动画和补间动画的区别
- Android中属性动画和补间动画的区别
- (转)Android中属性动画和补间动画的区别
- 简单的平移属性动画和补间动画区别
- android 帧动画,补间动画,属性动画区别
- 帧动画,补间动画,属性动画的区别
- Android属性动画和View动画(补间动画)
- Android的帧动画、补间动画、属性动画
- Android中View动画的学习掌握(补间动画,属性动画)
- android中的动画:帧动画、补间动画、属性动画
- Android动画:帧动画、补间动画、属性动画
- Android动画 帧动画、补间动画、属性动画 (一)
- Android动画 帧动画、补间动画、属性动画 (二)
- android属性动画与补间动画的区别及用法
- android 补间动画 属性动画 总结
- android补间动画,属性动画总结
- java中换行字符怎么用?
- java集合讲解
- 1Android APK瘦身
- MySQL索引原理及慢查询优化
- Android studio编译安装到小米5手机上,每次手机都要弹窗重新安装apk
- Android中属性动画和补间动画的区别
- Maven讲解之 POM.XML
- C# 中的var关键字
- 杜教模板(转载一篇cpp文件)
- java虚拟机学习
- java中的URLEncoder和URLDecoder类
- Android 性能测试之方向与框架篇
- React Native使用Expo真机调试检测不到state解决方法
- OKhttp讲解及各种协议