android 触摸事件冒泡动画效果
2013-10-30 14:46
134 查看
原图魔法效果:(透明的有些看不清)
PS之后加了背景色并放大后的效果
在屏幕中的效果(左上很小的那个,其他都是背景图):
中间很小的那个就是
先看动画实现代码explosion.xml(explosion意思是爆发)
代码片段,双击复制
手指点击后产生泡泡的动画是5张40*40的图片顺序播放产生的,每张持续时间为70毫秒,播放模式为oneshot,即一次。
BubbleExplosion.java:
注意:
1. exv1.setBackgroundResource(R.anim.explosion);
exv1是继承自ImageView的视图,看到他将一个animation设置成背景了,惊讶!原来动画可以设置为背景图。
2. exa1 = (AnimationDrawable)exv1.getBackground();
exa1.start();
不仅仅Aniamtion有start()方法,原来AnimationDrawable作为一个Drawable的子类也可以有start()方法哦。
没见过吧,之前我也没见过;见过啦?我现在也见过了!
再补充几个常识性的
3.setContentView(fl);
用代码绘制布局,完全没用到layout/main.xml~~
原码下载:http://download.csdn.net/detail/heng615975867/6476205
PS之后加了背景色并放大后的效果
在屏幕中的效果(左上很小的那个,其他都是背景图):
中间很小的那个就是
先看动画实现代码explosion.xml(explosion意思是爆发)
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@drawable/explode1" android:duration="70" /> <item android:drawable="@drawable/explode2" android:duration="70" /> <item android:drawable="@drawable/explode3" android:duration="70" /> <item android:drawable="@drawable/explode4" android:duration="70" /> <item android:drawable="@drawable/explode5" android:duration="70" /> </animation-list>
手指点击后产生泡泡的动画是5张40*40的图片顺序播放产生的,每张持续时间为70毫秒,播放模式为oneshot,即一次。
BubbleExplosion.java:
package com.ray.bubble; import android.app.Activity; import android.content.Context; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.View.OnTouchListener; import android.widget.FrameLayout; import android.widget.ImageView; public class BubbleExplosion extends Activity { private FrameLayout fl; private ExplosionView exv1; private AnimationDrawable exa1; // private Contact contact; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //set full screen requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN); fl = new FrameLayout(this); fl.setBackgroundResource(R.drawable.bg); exv1 = new ExplosionView(this); exv1.setVisibility(View.INVISIBLE); exv1.setBackgroundResource(R.anim.explosion); exa1 = (AnimationDrawable)exv1.getBackground(); fl.addView(exv1); fl.setOnTouchListener(new LayoutListener()); setContentView(fl); } class ExplosionView extends ImageView{ public ExplosionView(Context context) { super(context); } //handle the location of the explosion public void setLocation(int top,int left){ this.setFrame(left, top, left+40, top+40); } } class LayoutListener implements OnTouchListener{ public boolean onTouch(View v, MotionEvent event) { //first u have to stop the animation,or if the animation //is starting ,u can start it again! exv1.setVisibility(View.INVISIBLE); exa1.stop(); float x = event.getX(); float y = event.getY(); exv1.setLocation((int)y-20, (int)x-20); exv1.setVisibility(View.VISIBLE); exa1.start(); return false; } } }
注意:
1. exv1.setBackgroundResource(R.anim.explosion);
exv1是继承自ImageView的视图,看到他将一个animation设置成背景了,惊讶!原来动画可以设置为背景图。
2. exa1 = (AnimationDrawable)exv1.getBackground();
exa1.start();
不仅仅Aniamtion有start()方法,原来AnimationDrawable作为一个Drawable的子类也可以有start()方法哦。
没见过吧,之前我也没见过;见过啦?我现在也见过了!
再补充几个常识性的
3.setContentView(fl);
用代码绘制布局,完全没用到layout/main.xml~~
原码下载:http://download.csdn.net/detail/heng615975867/6476205
相关文章推荐
- Android.mk FILE_LIST遍历
- Android的NDK开发(3)————JNI数据类型的详解
- 第一个android程序
- Android笔记之Thread内部不要处理数据
- android 之Fragment(官网资料翻译)
- Android NDK环境搭建及调用JNI的简单步骤
- android PopupWindow
- Android类库常用类库一览
- Android实战技巧:用TextView实现Rich Text---在同一个TextView中设置不同的字体风格
- Android学习篇章3-Gallery画廊-Baseadapter
- Pro Android学习笔记(四七):Dialog(4):一些补充和思考
- Android.mk的用法和基础
- android开发 通过拍照或选择本地图片并剪裁图片设置成头像
- Android学习篇章2-Drop雨滴效果
- Android 解析后台返回为Json数据的简单例子
- android merge set background not work
- [Android]获取局域网广播地址的两种方法
- Android系统源代码下载
- android_布局属性大全
- android 设置控件的颜色字体的方法