Android动画的两种方式,其中帧动画上篇文章已经讲了,这次主要讲解的就是补间动画,补间动画就是动画业务场景中常用的旋转,平移,缩放,和渐变效果,帧动画是通过轮播动画实现动画效果,补间动画通过在两个关键帧之间补充渐变的动画效果来实现的,相对而言补间动画的暂用的空间更小,补间动画有两种方式,一种是直接在代码中是实现,另外一种是在XML文件中定义,然后通过代码调用,如果以后有需要直接改xml文件就行不需要改代码。

布局文件

先来看下是实现的效果:

Layout中xml设置:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.googletween.MainActivity" > <LinearLayout
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <Button
android:onClick="alphaEvent"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="渐变"
/> <Button
android:onClick="roateEvent"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="旋转"
/> <Button
android:onClick="tranEvent"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="位移"
/> <Button
android:onClick="scaleEvent"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="缩放"
/> <Button
android:onClick="multiEvent"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" android:text="混合"
/>
</LinearLayout> <ImageView
android:id="@+id/image_change"
android:layout_width="wrap_content"
android:layout_below="@id/line"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher"
/> </RelativeLayout>

 动画效果

渐变透明度,初始化构造函数的时候两个数字最小透明度和最大透明度:

 	AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f, 1f);
//设置动画时间
alphaAnimation.setDuration(3000);
//重复次数
alphaAnimation.setRepeatCount(1);
alphaAnimation.setRepeatMode(Animation.REVERSE);
image.startAnimation(alphaAnimation);

 旋转效果,初始化的时候是旋转0度到360度:

RotateAnimation rotateAnimation=new RotateAnimation(0f, 360f);
rotateAnimation.setDuration(2000);
image.startAnimation(rotateAnimation);

  位移效果,第一个参数fromXDelta ,第二个参数toXDelta:分别是动画起始、结束时X坐标,第三个参数fromYDelta ,第四个参数toYDelta:分别是动画起始、结束时Y坐标:

	TranslateAnimation translateAnimation=new TranslateAnimation(0f, 100f, 0f, 100f);
translateAnimation.setDuration(2000);
image.startAnimation(translateAnimation);

  缩放效果

   	ScaleAnimation scaleAnimation=new ScaleAnimation(0.1f, 1f, 0.1f, 1f);
scaleAnimation.setDuration(2000);
image.startAnimation(scaleAnimation);

  缩放的同时移动(最后两种效果混合):

AnimationSet  animationSet=new AnimationSet(true);
TranslateAnimation translateAnimation=new TranslateAnimation(0f, 100f, 0f, 100f);
ScaleAnimation scaleAnimation=new ScaleAnimation(0.1f, 1f, 0.1f, 1f); animationSet.addAnimation(translateAnimation);
animationSet.addAnimation(scaleAnimation);
animationSet.setDuration(2000);
image.startAnimation(animationSet);

 第二种是在xml文件中定义,将代码中的属性值在xml中设置即可:

渐变xml

<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="2000"
android:repeatCount="1"
android:repeatMode="reverse"> </alpha>

  调用:

   	Animation alphaAnimation=AnimationUtils.loadAnimation(this, R.anim.alpha);
image.startAnimation(alphaAnimation);

旋转xml:

<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromDegrees="0"
android:toDegrees="360"> </rotate>

  调用:

	Animation rotateAnimation=AnimationUtils.loadAnimation(this, R.anim.roate);
image.startAnimation(rotateAnimation);

  缩放xml:

<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="0"
android:toXScale="1"
android:fromYScale="0"
android:toYScale="1"> </scale>

  调用:

  	Animation scaleAnimation=AnimationUtils.loadAnimation(this, R.anim.scale);
image.startAnimation(scaleAnimation);

  位移xml:

<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXDelta="0"
android:toXDelta="100"
android:fromYDelta="0"
android:toYDelta="100"> </translate>

  调用:

Animation translateAnimation=AnimationUtils.loadAnimation(this, R.anim.tran);
image.startAnimation(translateAnimation);

组合xml:

<?xml version="1.0" encoding="utf-8"?>
<set> <alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromAlpha="0.1"
android:repeatCount="1"
android:repeatMode="reverse"
android:toAlpha="1.0" >
</alpha> <rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromDegrees="0"
android:toDegrees="360" >
</rotate> <scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXScale="0"
android:fromYScale="0"
android:toXScale="1"
android:toYScale="1" >
</scale> <translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100"
android:toYDelta="100" >
</translate> </set>

  调用:

Animation animationSet=AnimationUtils.loadAnimation(this, R.anim.set);
image.startAnimation(animationSet);

Android动画-补间(Tween)动画的更多相关文章

  1. js 动画补间 Tween

    1 /* RunningList (触发过程中可以安全的删除自己) 2 如果触发过程中删除(回调函数中删除正在遍历的数组), 不仅 len 没有变(遍历前定义的len没有变, 真实的len随之减少), ...

  2. Tween(补间)动画

    视图动画,也叫Tween(补间)动画可以在一个视图容器内执行一系列简单变换(位置.大小.旋转.透明度).譬如,如果你有一个TextView对象,您可以移动.旋转.缩放.透明度设置其文本,当然,如果它有 ...

  3. Android(java)学习笔记199:Android中补间动画(Tween Animation)

    本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画,可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1. ...

  4. Android(java)学习笔记142:Android中补间动画(Tween Animation)

    本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画, 可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1 ...

  5. android 帧动画,补间动画,属性动画的简单总结

      帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...

  6. Android笔记(六十四) android中的动画——补间动画(tweened animation)

    补间动画就是只需要定义动画开始和结束的位置,动画中间的变化由系统去补齐. 补间动画由一下四种方式: 1.AplhaAnimation——透明度动画效果 2.ScaleAnimation ——缩放动画效 ...

  7. 属性动画 补间动画 帧动画 基本使用案例 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)

    Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变). 第二类就是 Frame动画,即顺序的播放事先做好的图像,与g ...

  9. Android 动画 属性动画 视图动画 补间动画 帧动画 详解 使用

    Android动画 Property Animation res/animator/filename.xml In Java: R.animator.filename In XML: @[packag ...

随机推荐

  1. Python网络编程之socket应用

    1 引言 本篇主要对Python下网络编程中用到的socket模块进行初步总结.首先从网络基础理论出发,介绍了TCP协议和UDP协议:然后总结了socket中的常用函数:最后通过实际代码展示基本函数的 ...

  2. Java 中的国际化

    国际化 ,英文叫 internationalization 单词太长 ,又被简称为 i18n(取头取尾中间有18个字母)不经大声呼喊 ,这都行 !接着看什么是国际化 , 国际化是指让产品或是程序在无需 ...

  3. win10怎么修改svn的用户和密码

    win10怎么修改svn的用户和密码(一般为默认),其他的系统也差不多 方法/步骤 1.方法一: 1.双击我的电脑在c盘找到auth文件夹 C:\Users\系统帐户名\AppData\Roaming ...

  4. [leetcode trie]212. Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  5. poj2676(数独)

    也是一个简单剪枝的dfs.记录所有为0的位置,依次填写,当发现某个空格可选的填写数字已经没有时,说明该支路无效,剪掉. 不算是一个难题吧,但是还是花了不少时间,问题主要出在细节上,行列坐标反了.3乘3 ...

  6. KVM libvirt的CPU热添加

    一. NUMA1. NUMA 介绍    早期的时候,每台服务器都是单CPU,随着技术的发展,出现了多CPU共同工作的需求.    NUMA(Non-Uniform Memory Access,非一致 ...

  7. [ 原创 ]学习笔记-Android 中关于Cursor类的介绍

    此博文转载自:http://www.cnblogs.com/TerryBlog/archive/2010/07/05/1771459.html 主讲Cursor的用法 使用过 SQLite 数据库的童 ...

  8. PHP大型电商网站秒杀思路

    秒杀/抢购 技术:高可用,高并发 市场:用户体验,曝光度,促销 秒杀放单独服务器,这样即使崩溃不影响网站其他功能. 高可用:双活. 高并发:负载均衡,安全过滤. 阿里云:云监控 分流,CDN加速 业务 ...

  9. 【20181031T1】一串数字【分解质因数+贪心】

    题面 [错解] 立方就是所有质因子次数都是3的倍数嘛 发现1e5的三次根很小,可以枚举所有和这个数乘起来是完全立方数的(flag*1) 然后--连条边跑最大独立集? 不对啊是NP问题(实际上是个二分图 ...

  10. SPOJ GSS

    GSS1 题目大意:给出一个数列,多次询问区间最长连续子段和 题解:线段树维护区间最长连续子段和gss,区间从最左元素开始的最长连续子段和lgss 区间以最右元素为结尾的最长连续子段和rgss以及区间 ...