- 浏览: 752500 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (139)
- 玩转Android (48)
- Android创意美工 (0)
- Android杂谈 (23)
- Android实例练习 (2)
- Android ROM研究 (5)
- Android NDK开发指南 (5)
- Android NDK (0)
- Android Tips (3)
- Windows Phone 7 (5)
- iPhone (0)
- HTML5学习室 (0)
- JAVA (9)
- SSH+ibatis (8)
- PHP (0)
- IT生活 (1)
- linux (2)
- C (4)
- C++ (1)
- web 前端 (1)
- 云计算 (0)
- 设计模式 (0)
- C# (2)
- 其他 (1)
- 数据结构 (5)
- Web开发 (10)
- 数据库 (3)
- 搜索引擎 (0)
- Go语言 (0)
最新评论
-
wi100sh:
多谢分享~
玩转Android---UI篇---ImageButton(带图标的按钮) -
zhanghaichang:
好文章的。
高性能web开发技术(一) -
yingang:
引用classes.dex.dex2jar.jar 拖入 j ...
Andorid杂谈---Apk文件的反编译 -
扶摇诺:
讲解的简明易懂,多谢啦!
玩转Android---UI篇---LinearLayout(线性布局) -
a13429921973:
更为详细的图文介绍,可参考这个http://blog.csdn ...
Android ROM研究---CyanogenMod源代码下载及编译
玩转Android---2D图形及动画---动画分析(Tween详细分析)
- 博客分类:
- 玩转Android
在Android系统中提供了两种动画实现方式:一种是Tween动画,这种实现方式可以使视图组件移动、放大、缩小以及产生透明度的变化;另一种方式是Frame动画,这是逐帧动画,通过顺序播放排列好的图片来实现的,类似电影。
Tween动画:
Tween动画能完成一系列简单的变化(如位置、尺寸、透明度和旋转等)。例如,在你的程序中有一个ImageView组件,我们通过Tween动画可以使该视图实现放大、缩小、旋转、渐变等。Tween动画类位于android.view.animation包中,该包中包含了一些常用的动画实现类。
- Animation:动画抽象类,其他几个实现类继承它
- ScaleAnimation:控制尺寸变化的动画类
- AlphaAnimation:控制透明度变化的动画类
- RotateAnimation:控制旋转变化的动画类
- TranslateAnimation:控制位置变化的动画类
- AnimationSet:定义动画属性集合类
- AnimationUtils:动画工具类
常用构造方法 |
参数说明 |
AlphaAnimation(float fromAlpha, float toAlpha) |
fromAlpha:动画开始透明度 toAlpha:动画结束透明度(取值范围0.0~1.0) 1.0表示完全不透明 0.0表示完全透明 |
ScaleAnimation(float fromX, float toX,float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) |
fromX:起始X坐标上的伸缩尺寸 toX:结束X坐标上的伸缩尺寸 fromY:其实Y坐标上的伸缩尺寸 toY:结束Y坐标上的伸缩尺寸 pivotXType:X坐标伸缩模式(取值Animation.ABSOLUTE、Animation.RELATIVE_TO_SELF、Animation.RELATIVE_TO_PARENT) pivotXValue:相当于X坐标伸缩值 pivotYType:Y坐标伸缩模式(取值 Animation.ABSOLUTE、 Animation.RELATIVE_TO_SELF、 Animation.RELATIVE_TO_PARENT) pivotYValue:相当于Y坐标伸缩值 |
TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) |
fromXDelta:其实X坐标 toXDelta:结束X坐标 fromYDelta:起始Y坐标 toYDelta:结束Y坐标 |
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, pivotYType, float pivotYValue) |
fromDegrees:旋转开始角度 toDegrees:旋转结束角度 pivotXType:X坐标伸缩模式(取值Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT) pivotXValue:相当于X坐标伸缩值 pivotYType:Y坐标伸缩模式(取值Animation.ABSULUTE, Animation.RELATIVE_TO_SELF,Animation.RELATIVE_TO_PARENT) pivotYValue:相当于Y坐标伸缩值 |
如果全部选择Animation.ABSOLUTE,其实就是第二个构造函数。
以x轴为例介绍参照与对应值的关系
如果选择参照为Animation.ABSOLUTE,那么对应的值应该是具体的坐标值,比如100到300,指绝对的屏幕像素单位
如果选择参照为Animation.RELATIVE_TO_SELF或者 Animation.RELATIVE_TO_PARENT指的是相对于自身或父控件,
对应值应该理解为相对于自身或者父控件的几倍或百分之多少。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/ScaleBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Scale" /> <Button android:id="@+id/AlphaBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Alpha" /> <Button android:id="@+id/TranslateBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Translate" /> <Button android:id="@+id/RotateBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Rotate" /> </LinearLayout> <ImageView android:id="@+id/Imageview01" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ni_png_0707" /> </LinearLayout>
package com.loulijun.AnimaitonTest; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends Activity { private Button scaleBtn,rotateBtn,alphaBtn,translateBtn; private ImageView img; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img = (ImageView)findViewById(R.id.Imageview01); scaleBtn = (Button)findViewById(R.id.ScaleBtn); rotateBtn = (Button)findViewById(R.id.RotateBtn); alphaBtn = (Button)findViewById(R.id.AlphaBtn); translateBtn = (Button)findViewById(R.id.TranslateBtn); scaleBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { //创建伸缩动画 Animation scaleAnimation = new ScaleAnimation(0f,1f,0f,1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //设置动画持续时间 scaleAnimation.setDuration(2000); //开始动画 img.startAnimation(scaleAnimation); } }); rotateBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //创建rotate旋转动画 Animation rotateAnimation = new RotateAnimation(0f, +36f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //设置动画持续时间 rotateAnimation.setDuration(2000); //开始动画 img.startAnimation(rotateAnimation); } }); translateBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 创建位置变化动画 Animation translateAnimation = new TranslateAnimation(10, 100, 10, 100); //设置动画持续时间 translateAnimation.setDuration(2000); //开始动画 img.startAnimation(translateAnimation); } }); alphaBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //创建渐变动画 Animation alphaAnimation = new AlphaAnimation(0.1f,1.0f); //设置动画持续时间 alphaAnimation.setDuration(2000); //开始动画 img.startAnimation(alphaAnimation); } }); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/ScaleBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Scale" /> <Button android:id="@+id/AlphaBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Alpha" /> <Button android:id="@+id/TranslateBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Translate" /> <Button android:id="@+id/RotateBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Rotate" /> </LinearLayout> <ImageView android:id="@+id/Imageview01" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ni_png_0707" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="2000" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="-180" android:pivotX="50%" android:pivotY="50%" android:duration="2000" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="10" android:toXDelta="100" android:fromYDelta="10" android:toYDelta="100" android:duration="2000" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="2000" /> </set>
package com.loulijun.animationtest2; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends Activity { private Button alphaBtn,rotateBtn,translateBtn,scaleBtn; private ImageView img; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img = (ImageView)findViewById(R.id.Imageview01); alphaBtn = (Button)findViewById(R.id.AlphaBtn); rotateBtn = (Button)findViewById(R.id.RotateBtn); translateBtn = (Button)findViewById(R.id.TranslateBtn); scaleBtn = (Button)findViewById(R.id.ScaleBtn); alphaBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { //设置渐变动画 Animation alphaAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.myalpha); //开始动画 img.startAnimation(alphaAnimation); } }); rotateBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { //设置旋转动画 Animation rotateAnimation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.myrotate); //开始动画 img.startAnimation(rotateAnimation); } }); translateBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { //设置位置变化动画 Animation translateAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.mytranslate); //开始动画 img.startAnimation(translateAnimation); } }); scaleBtn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { //创建伸缩动画 Animation scaleAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.myscale); //开始动画 img.startAnimation(scaleAnimation); } }); } }
发表评论
-
玩转Android---2D图形及动画---图片处理
2011-09-26 13:08 1718在Android中很多地方都使 ... -
玩转Android--UI篇--PreferenceActivity(开启wifi和音乐等)
2011-09-01 11:57 4775本测试主要是为了测试PreferenceActivity的使用 ... -
玩转Android---2D图形及动画---Gif动画
2011-08-05 09:36 2159由于Gif本身就是动画,所以如果能够直接使用的话,会省去很多的 ... -
玩转Android---2D图形及动画---Frame动画
2011-08-01 20:53 2023Frame动画其实就是逐帧动画,用法也比Tween动画简单,只 ... -
玩转Android---2D图形及动画---Tween动画
2011-07-31 22:53 2132Android平台提供了两类动画,分别是Tween动画,和Fr ... -
玩转Android---2D图形及动画---View类使用
2011-07-30 23:39 2750由于游戏界面是由大量美工资源图片构成的,所以,在设计游戏界面的 ... -
玩转Android--组件篇---Handler的使用
2011-07-30 14:01 5304public class Handler ... -
玩转Android---UI篇---ZoomControls放大缩小图片
2011-07-27 13:03 7205ZoomControls控件是一个可以缩放但控件,效果如下图 ... -
玩转Android---组件篇---TextSwitcher
2011-07-25 09:21 2145还记得有一次淘宝的电话面试的时候问了我一个关于Android的 ... -
玩转Android---组件篇---AnalogClock,DigitalClock
2011-07-10 19:28 2875首先要说的是,这两个控件并不是经常的使用,但是如果程序需要的话 ... -
玩转Android---组件篇---SeekBar,RatingBar,Chronometer
2011-07-10 19:12 2801今天补充三个组件的使用,避免日后忘记。它们分别是 SeekB ... -
玩转Android---组件篇---Handler的使用(2)
2011-05-28 17:15 2755对于Handler来说,它和与它调用它的Activity是出于 ... -
玩转Android---组件篇---Handler的使用(1)
2011-05-28 15:37 2107在android中,有很多功能是不能放在onCreate或者o ... -
玩转Android---事件监听篇---第2篇
2011-05-27 10:30 5192事件监听篇---第二篇 下面是各种常用控件的事件监听的 ... -
玩转Android---事件监听篇---第1篇
2011-05-26 21:29 9890事件就是用户与UI界面的交互时所触发的操作。比如点击某一个按钮 ... -
玩转Android---组件篇---数据存储之SQLite
2011-04-17 17:05 8430Android中通过SQLite数据库引擎来实现结构化数据存储 ... -
玩转Android---组件篇---数据存储之File
2011-04-17 11:07 1996我们可以将一些数据直接以文件的形式保存在设备中。例如,一些文本 ... -
玩转Andorid---组件篇---数据存储之preference
2011-04-14 21:58 2250程序是数据的输入、处 ... -
玩转Android---组件篇---Broadcast Receiver(广播接收器)
2011-04-14 19:24 29249Braodcast Receiver顾名思义 ... -
玩转Andorid---组件篇---Service(服务)之RPC远程进程调用
2011-04-08 21:17 3392在Andorid平台中,各个组件运行在自己的进程中,他们 ...
相关推荐
Android---Tween动画 运用了4种Tween的动画效果,包括: rotate(旋转),scale(伸缩), alpha(透明度),translate(平移) 以及tween(综合4种效果)
Android 平台提供了两类动画。 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转、平移、放缩和渐变);第二类就是 Frame动画,即顺序的播放事先做好的图像,与gif图片原理类似。 本例子...
Android Tween动画源码,实现了android Tween动画的alpha、scale、translate、rotate四种效果
Android tween动画代码实现,包含alpha、scale、translate、rotate,都是动态代码实现,里面有详细的注释
android Tween动画的xml实现
相关博客见 http://blog.csdn.net/wzg_1987/article/details/8842661
android开发中的Tween动画,动画演示demo。 此demo为android studio 2.0 所写.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
雨松MOMO带你做游戏 Android 游戏开发之Tween动画的实现 欢迎大家下载阅读 哇咔咔~~~
Android基础——Tween动画、Drawable动画、Property动画、MaterialDesign动画、Trasition动画
rc-tween-one ReactTweenOne组件 浏览器支持 IE 10以上 :check_mark: Chrome31.0+ :check_mark: Firefox 31.0+ :check_mark: Opera 30.0+ :check_mark: Safari 7.0以上 :check_mark: 发展 npm install npm ...
前端项目-es6-tween,ES6实现惊人的tween.js
动画库 博文链接:https://gundumw100.iteye.com/blog/1108830
android Tween动画概括+示例 中代码例子。
这是一个通过android xml的形式实现Tween动画的四种形式,包括:alpha渐变动画、rotate旋转动画、translate位移动画、scale缩放动画。另外还有一个集合动画。
tween自动动画
该Demo,主要以xml形式实现了Animation动画中的Tween动画(另一种动画Frame动画Demo,稍后奉上),Tween动画的另一种实现形式是直接在代码中实现,相关Demo已上传,有需要的读者请到我的资源文件中下载即可。
Android 百战经典-Android补间动画(Tween)大观园,博客:http://blog.csdn.net/yayun0516
博客地:http://blog.csdn.net/dmk877/article/details/51912104,详细讲解了Tween动画的用法。
基于Android 游戏开发之Tween动画的实现
Android TweenAnimation动画源码