View Animation, 它显示在view向上Tween Animation

Tween动画。本质上没有变化View对象本身。只要改变它绘制

实施方式有两种。一个xml定义,直接在代码中的定义

xml定义方式:

位移动画translate

<?

xml version="1.0" encoding="utf-8"?

>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="10"
android:fromYDelta="0"
android:toXDelta="50%"
android:toYDelta="50%p"
android:repeatCount="50"
android:repeatMode="reverse"
android:fillAfter="true">
<!-- repeatCount 动画再次反复的次数
repeatMode 这一次反转上一次的效果
fillAfter 动画结束后,view停留在动画结束时的位置 view的实际位置并没有改变
50%p 相对于父布局
50% 相对于自身
-->
</translate>

旋转动画rotate

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:fillAfter="true">
<!--
fromDegrees="0" 開始角度
toDegrees="-90" 结束角度
pivotX="50%" 中心点x
pivotY="50%" 中心点y
-->
</rotate>

透明度渐变动画alpha

<?

xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" >
<!--
fromAlpha 開始的透明度 0全然透明
toAlpha 结束的透明度 1全然不透明
-->
</alpha>

缩放动画scale

<?

xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="0.5"
android:fromYScale="1"
android:toXScale="3"
android:toYScale="2"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" >
<!--
scale 缩放比率
-->
</scale>

动画集

<?

xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" > <scale
android:fromXScale="0.5"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:toXScale="3"
android:toYScale="2" /> <alpha
android:fromAlpha="0"
android:repeatCount="50"
android:repeatMode="reverse"
android:toAlpha="1" /> <translate
android:fromXDelta="10"
android:fromYDelta="0"
android:repeatCount="50"
android:repeatMode="reverse"
android:toXDelta="50%"
android:toYDelta="50%p" /> <rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:toDegrees="-100" /> </set>

代码载入这些xml定义的动画

	Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate);
imageview_translate.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_translate.startAnimation(translate); Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
imageview_rotate.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_rotate.startAnimation(rotate); Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha);
imageview_alpha.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_alpha.startAnimation(alpha); Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale);
imageview_scale.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_scale.startAnimation(scale); Animation set = AnimationUtils.loadAnimation(this, R.anim.set);
imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_set.startAnimation(set);

纯代码创建Tween Animation

AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(scale);
animationSet.addAnimation(translate);
animationSet.addAnimation(alpha);
animationSet.addAnimation(rotate);
animationSet.setDuration(2000);
animationSet.setRepeatCount(50);
animationSet.setRepeatMode(Animation.RESTART);
// animationSet.setRepeatMode(Animation.REVERSE);
imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_set.startAnimation(animationSet); TranslateAnimation translateAnimation;
RotateAnimation rotateAnimation;
AlphaAnimation alphaAnimation;
ScaleAnimation scaleAnimation;
// Animation.RELATIVE_TO_SELF 相对于自身
// Animation.RELATIVE_TO_PARENT 相对于父View

设置动画监听器

	scale.setAnimationListener(new AnimationListener() {

				@Override //动画開始
public void onAnimationStart(Animation animation) { } @Override //动画反复
public void onAnimationRepeat(Animation animation) { } @Override //动画结束
public void onAnimationEnd(Animation animation) { }
});

动画插入器Interpolator

在animation的xml和代码中 能够设置动画的插入器。它用来指示动画在持续时间内的动作的速率变化

android:interpolator="@android:anim/overshoot_interpolator"OvershootInterpolator

 <!--
默认情况下:动画随着时间的推移 均匀的被应用,要改变这样的效果能够使用插入器
interpolator 设置插入器
accelerate_interpolator 相似加速度先小后大, 開始慢 后渐快 变速运动
accelerate_decelerate_interpolator 相似加速度先大后小, 先加速 后减速 变速运动 anticipate_interpolator the change starts backward then flings forward 先减(减到比開始值还小一点),后加(加到结束值)
anticipate_overshoot_interpolator 先减(减到比開始值还小一点),后加(加到比结束值还大一点。再回退到结束值)
overshoot_interpolator 直接加速到结束值。并比结束值还大一点,再回退到结束值 bounce_interpolator 反弹结束时的变化 到达结束值时一会小一会大 来回两次
cycle_interpolator 先高速从開始到结束值,再遵循正弦模式继续运动 (左右对切,上下对切)
linear_interpolator 相似加速度为0,速率不变, 匀速运动 不定义插入器时使用的默认值 -->

版权声明:本文博主原创文章,博客,未经同意不得转载。

Android Tween Animation的更多相关文章

  1. 深入Animation,在SurfaceView中照样使用Android—Tween Animation!

    第一类:Frame By Frame 帧动画( 不推荐游戏开发中使用)             所谓帧动画,就是顺序播放事先做好的图像,类似于放电影:             分析: 此种方式类似我之 ...

  2. android tween animation合集

    自己写的一些tween animation动画xml文件,可用于activity切换,图片切换动画等 http://files.cnblogs.com/zj2012zy/anim.rar

  3. android之Tween Animation

    android Tween Animation有四种,AlphaAnimation(透明度动画).ScaleAnimation(尺寸伸缩动画).TranslateAnimation(位移动画).Rot ...

  4. Android动画效果之Tween Animation(补间动画)

    前言: 最近公司项目下个版本迭代里面设计了很多动画效果,在以往的项目中开发中也会经常用到动画,所以在公司下个版本迭代开始之前,抽空总结一下Android动画.今天主要总结Tween Animation ...

  5. Android动画学习(二)——Tween Animation

    前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...

  6. Android动画Animation之Tween用代码实现动画

    透明度动画.旋转动画.尺寸伸缩动画.移动动画 package com.javen.tween; import android.annotation.SuppressLint; import andro ...

  7. Android开发UI之补间动画-Tween Animation

    Tween Animation-补间动画 官网链接-http://developer.android.com/reference/android/view/animation/Animation.ht ...

  8. Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)

    1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...

  9. 详解Android动画之Tween Animation

    前面讲了动画中的Frame动画,今天就来详细讲解一下Tween动画的使用. 同样,在开始实例演示之前,先引用官方文档中的一段话: Tween动画是操作某个控件让其展现出旋转.渐变.移动.缩放的这么一种 ...

随机推荐

  1. Android 网络编程 Socket Http

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  2. jquery validation remote depends 验证触发条件

    背景: 1:简介页面的变化: 2:邮箱不能反复 改动页面,邮箱默认带出,但字段上带有remote验证.不能反复,焦点由邮箱输入框失去时.会默认触发remote验证. 介绍完成 watermark/2/ ...

  3. NYOJ 104 最大子矩阵(二维DP)

    最大和 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描写叙述 给定一个由整数组成二维矩阵(r*c),如今须要找出它的一个子矩阵,使得这个子矩阵内的全部元素之和最大,并把这个 ...

  4. 解决Android Device Chooser 找不到设备问题

    第一种情况: 已经启动了官方的模拟器也进入了Android手机界面,可是在Android Device Chooser 看不到设备,怎么办? 例如以下图所看到的,使用Reset adb 或者在adb所 ...

  5. Windows Phone开发(8):关于导航的小技巧

    原文:Windows Phone开发(8):关于导航的小技巧 前文用几个例子对导航做了简单介绍,在一般应用中,使用上一篇文章中说到的方法,其实也够用了,不过,为了能够处理一些特殊的情况,有几个小技巧还 ...

  6. 对HGE游戏引擎的一次封装

    HGE游戏引擎是一个开源2D游戏引擎,基于directX. 它的渲染及逻辑是基于帧回调的框架模式, 其提供一些主要的图像操作和输入控制功能. 我在之前写一个2D游戏的时候对它整个框架进行了一次封装,非 ...

  7. Android4.0设置接口变更摘要(四)

    为了与你之前,你已经设置了共享Tab风格和Item实现圆角.希望能给有须要的朋友一点点帮助,今天再和大家分享一下用ViewPager实现设置分页,小米和OPPO就是这种设置,先来看看效果图: wate ...

  8. android 泰国/缅甸语/捷克较低,Contacts联系出现精神错乱之类的问题清单

    更改ContactsProvider2.java文件 public static final String SECTION_HEADING = "SUBSTR(%1$s,1,1)" ...

  9. Perl中的单行凝视和多行凝视

    同其它大多数编程语言一样.Perl中的单行凝视也是#开头.比如: #print "Hello,World!"; 但多行凝视.不同的语言有不同的凝视方式,比方说: Java,C/C+ ...

  10. 【原创】leetCodeOj ---Construct Binary Tree from Preorder and Inorder Traversal 解题报告

    原题地址: https://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 题目 ...