Android中TweenAnimation四种动画切换效果
点击每个按钮都会有对应的动画显示
activity代码:
package com.tmacsky;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class AnimationDemoActivity extends Activity {
private ImageView imageView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//定义四个动画的button属性
imageView = (ImageView)findViewById(R.id.imageView);
Button alpha = (Button)findViewById(R.id.Alpha);
alpha.setOnClickListener(new AnimationClickListener(AnimationType.Alpha));
Button rotate = (Button)findViewById(R.id.Rotate);
rotate.setOnClickListener(new AnimationClickListener(AnimationType.Rotate));
Button scale = (Button)findViewById(R.id.Scale);
scale.setOnClickListener(new AnimationClickListener(AnimationType.Scale));
Button translate = (Button)findViewById(R.id.Translate);
translate.setOnClickListener(new AnimationClickListener(AnimationType.Translate));
Button complex = (Button)findViewById(R.id.Complex);
complex.setOnClickListener(new AnimationClickListener(AnimationType.Complex));
}
//定义animationType属性
enum AnimationType{
Alpha,
Rotate,
Scale,
Translate,
Complex
}
//定义一个函数
class AnimationClickListener implements OnClickListener{
private AnimationType animationType;
public AnimationClickListener(AnimationType animType){
animationType = animType;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (animationType) {
case Alpha:
//定义渐变动画,重复5次,持续1分钟
/*AlphaAnimation _animation = new AlphaAnimation(1f, 0.1f);
_animation.setDuration(3000);
_animation.setRepeatCount(5);
//设置循环
_animation.setRepeatMode(Animation.REVERSE);
_animation.setAnimationListener(new AnimationListener() {
//设置animation监听,依次是启动,重复,然后结束
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.i("log", "animation Start");
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.i("log", "animation Repeat");
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.i("log", "animation End");
}
});
//启动动画
imageView.startAnimation(_animation);*/
AlphaAnimation alphaAnimation = (AlphaAnimation)AnimationUtils.loadAnimation(AnimationDemoActivity.this, R.anim.alpha);
imageView.startAnimation(alphaAnimation);
break;
case Rotate:
//定义旋转动画,旋转一周持续1分钟,重复三次,在物体的中心位置
RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(3000);
rotateAnimation.setRepeatCount(3);
//启动动画
imageView.startAnimation(rotateAnimation);
break;
case Scale:
//定义缩放动画,从中心坐标开始,缩放1.5倍大小,持续1分钟,重复三次
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 1.5f, 1, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(3000);
scaleAnimation.setRepeatCount(3);
//启动动画
imageView.startAnimation(scaleAnimation);
break;
case Translate:
//定义移动动画,都从自身坐标开始,移动2个位置,持续1分钟,重复三次
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2);
translateAnimation.setDuration(3000);
translateAnimation.setRepeatCount(3);
//启动动画
imageView.startAnimation(translateAnimation);
break; case Complex:
//设置复杂的操作步骤,点击按钮complex后,会运行四种动画效果叠加
AnimationSet sets = new AnimationSet(false);
//定义渐变动画
AlphaAnimation _animation1 = new AlphaAnimation(1f, 0.1f);
_animation1.setDuration(3000);
//定义旋转动画,在物体的中心位置
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setDuration(3000);
//定义缩放动画,从中心坐标开始,缩放1.5倍大小
ScaleAnimation scaleAnimation1 = new ScaleAnimation(1, 1.5f, 1, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation1.setDuration(3000);
//定义移动动画,都从自身坐标开始,移动2个位置
TranslateAnimation translateAnimation1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2);
translateAnimation1.setDuration(3000);
//启动动画
sets.addAnimation(_animation1);
sets.addAnimation(rotateAnimation1);
sets.addAnimation(scaleAnimation1);
sets.addAnimation(translateAnimation1);
imageView.startAnimation(sets);
break;
default:
break;
}
}
}
}
layout文件:
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/qa" />
<Button
android:id="@+id/Alpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alpha" />
<Button
android:id="@+id/Rotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate" />
<Button
android:id="@+id/Scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scale" />
<Button
android:id="@+id/Translate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Translate" />
<Button
android:id="@+id/Complex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Complex" />
</LinearLayout>
资源anim文件alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1" android:toAlpha="0.3" android:duration="2000" android:repeatCount="3">
</alpha>
Android中TweenAnimation四种动画切换效果的更多相关文章
- Android中的四种动画(一)
TweenAnimation 变换动画(也叫作"补间动画"),有四种(alpha scale translate rote). FrameAnimation(也叫DrawableA ...
- Android中Button四种点击事件实现方式
1.Xml添加监听属性,这里添加的doClick. <Button android:id="@+id/bt1" android:layout_width="wrap ...
- Activity中的四种启动模式
在Android中每个界面都是一个Activity,切换界面操作其实是多个不同Activity之间的实例化操作.在Android中Activity的启动模式决定了Activity的启动运行方式. An ...
- Android中使用ImageViewSwitcher实现图片切换轮播导航效果
前面写过了使用ViewFlipper和ViewPager实现屏幕中视图切换的效果(ViewPager未实现轮播)附链接: Android中使用ViewFlipper实现屏幕切换 Android中使用V ...
- Android平台中的三种翻页效果机器实现原理
本文给开发者集中展现了Android平台中的三种翻页效果机器实现原理,希望能够对开发者有实际的帮助价值! 第一种翻页效果如下: 实现原理: 当前手指触摸点为a,则 a点坐标为(ax,ay), ...
- Android中的Drawable和动画
Android中Drawable是一种可以在Canvas上进行绘制抽象的概念,种类很多,常见的颜色和图片都可以是一个Drawable.Drawable有很多种,它们表示一种图像的概念,但是它们又不全是 ...
- Android Activity 的四种启动模式 lunchMode 和 Intent.setFlags();singleTask的两种启动方式。
原文:Android Activity 的四种启动模式 lunchMode 和 Intent.setFlags();singleTask的两种启动方式. Android Activity 的四种启动模 ...
- Android - TabHost 与 Fragment 制作页面切换效果
Android - TabHost 与 Fragment 制作页面切换效果 Android API 19 , API 23 三个标签页置于顶端 效果图: 在文件BoardTabHost.java中定义 ...
- 使用AnimateWindow来实现窗口淡入淡出(主要有四种动画,滚动,滑动,折叠或展开,和淡入淡出)
如果是在VC6下进行编译,应引入下面的预编译宏,注意放在windows.h的前面#undef WINVER #define WINVER 0x500为什么要引入上面的宏呢?看看winuse ...
随机推荐
- D3D 练习小框架
自己练习D3D 程序搭的小框架,记录在这里,将来看到好回顾自己独自摸索的苦逼样子. #pragma once #pragma comment(lib,"d3d9.lib") #pr ...
- 【OpenMesh】Some basic operations: Flipping and collapsing edges
这一节中你将学到一些OpenMesh中早已提供的基础操作. 内容包括三角形网格边的翻转以及通过连接邻接的顶点边缘折叠. 三角形网格的翻转(Flipping edges) 考虑到两个邻接面的三角形网格中 ...
- 【虚拟化实战】容灾设计之三Stretched Cluster
作者:范军 (Frank Fan) 新浪微博:@frankfan7 Stretched Cluster是一把双刃剑,会用的如行云流水,用不好反而受其限制. 传统的vSphere Cluster是指一个 ...
- eclipse weblogic debug 简易配置版
1. eclipse->help->marketplace->search->weblogic 1.1安装对应eclipse版本的weblogic plugin 查看eclip ...
- T-SQL 操作文件 具体解释
/******* 导出到excel EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:\temp1.xls -c -q -S" ...
- Floodlight 处理交换机增加/移除过程
Floodlight 使用的是Netty架构,在Controller.java 入口函数中显示创建ServerBootstrap,设置套接字选项,ChannelPipeline,此时监听套接 ...
- Qt Windows下开机自动启动自己的程序
源地址:http://blog.csdn.net/chrisfxs/article/details/13279491 版权声明:本文为博主原创文章,未经博主允许不得转载. void Widget::R ...
- USM锐化之openCV实现,附赠调整对比度函数
源地址:http://www.cnblogs.com/easymind223/archive/2012/07/03/2575277.html 常用Photoshop的玩家都知道Unsharp Mask ...
- 搜索:POJ2251&POJ1426&POJ3087&POJ2488
图的遍历也称为搜索,就是从图中某个顶点出发,沿着一些边遍历图中所有的顶点,且每个顶点仅被访问一次,遍历可采取两种不同的方式:深度优先搜索(DFS)和广度优先搜索(BFS). 1.DFS算法思想` 从顶 ...
- ACM-简单题之Factorial——poj1401
转载请注明出处:http://blog.csdn.net/lttree Factorial Time Limit: 1500MS Memory Limit: 65536K Total Submis ...