package com.test.a;
import java.util.Random;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;
public class FlowerView extends View {
Bitmap mFlowers = null;
MyFlower flowers [] = new MyFlower[50];
private Integer[] offsetX ;
private Integer[] offsetY ;
Random r = new Random();
Matrix m = new Matrix();
Paint p = new Paint();
int mW = 480;
int mH = 800;
float de = 0f;
public void setWH(int pW, int pH, float de){
this.mW = pW;
this.mH = pH;
this.de = de;
System.out.println("de ---->" + de);
offsetX = new Integer[]{(int)(2*de), (int)(-2*de), (int)(-1*de), 0, (int)(1*de), (int)(2*de), (int)(1*de)};
offsetY = new Integer[]{(int)(3*de), (int)(5*de), (int)(5*de), (int)(3*de), (int)(4*de)};
}
public FlowerView(Context context) {
super(context);
}
public FlowerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FlowerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
for (int i = 0; i < flowers.length; i++) {
MyFlower rect = flowers[i];
int t = rect.t;
t--;
if (t <= 0) {
rect.y += rect.g;
canvas.save();
m.reset();
m.setScale(rect.s, rect.s);
canvas.setMatrix(m);
p.setAlpha(rect.a);
canvas.drawBitmap(mFlowers, rect.x, rect.y, p);
canvas.restore();
}
rect.t = t;
if (rect.y >= mH) {
rect.init();
}
if (rect.x >= mW || rect.x < - 20) {
rect.init();
}
flowers[i] = rect;
}
}
public void loadFlower(){
Resources r = this.getContext().getResources();
mFlowers = ((BitmapDrawable)r.getDrawable(R.drawable.snow)).getBitmap();
}
public void recly(){
if (mFlowers != null && !mFlowers.isRecycled()) {
mFlowers.recycle();
}
}
public void addRect(){
for (int i = 0; i < flowers.length; i++) {
flowers[i] = new MyFlower();
}
}
public void inva(){
invalidate();
}
class MyFlower{
int x;
int y;
float s;
int a;
int t;
int g;
public void init(){
float aa = r.nextFloat();
this.x = r.nextInt(mW - 80) + 80;
this.y = 0;
if (aa >= 1) {
this.s = 1.1f;
}else if (aa <= 0.2) {
this.s = 0.4f;
}else{
this.s = aa;
}
this.a = r.nextInt(155) + 100;
this.t = r.nextInt(105) + 1;
this.g = offsetY[r.nextInt(4)];
}
public MyFlower(){
super();
init();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
android动画-雪花飘落demo
共43个文件
png:12个
class:12个
xml:4个
5星 · 超过95%的资源 需积分: 35 142 下载量 37 浏览量
2015-10-29
11:00:39
上传
评论 5
收藏 88KB ZIP 举报
温馨提示
android动画-雪花飘落demo 参考文章:http://blog.csdn.net/yayun0516 欢迎关注我的博客。
资源推荐
资源详情
资源评论
收起资源包目录
VV.zip (43个子文件)
VV
bin
classes.dex 10KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
snow.png 2KB
crunch
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
snow.png 2KB
drawable-mdpi
ic_launcher.png 2KB
drawable-mdpi
ic_launcher.png 2KB
jarlist.cache 120B
dexedLibs
annotations-9564ccdbe362d2176ca30c06741196bc.jar 1KB
classes
com
test
a
MainActivity.class 2KB
BuildConfig.class 329B
MainActivity$2.class 848B
MainActivity$1.class 744B
R$layout.class 370B
R$id.class 364B
R$drawable.class 411B
R$attr.class 316B
R.class 475B
FlowerView$MyFlower.class 1KB
R$string.class 403B
FlowerView.class 4KB
resources.ap_ 13KB
VV.apk 20KB
AndroidManifest.xml 917B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
snow.png 5KB
drawable-xhdpi
values
strings.xml 174B
drawable-mdpi
ic_launcher.png 3KB
layout
main.xml 439B
assets
gen
com
test
a
BuildConfig.java 152B
R.java 788B
proguard.cfg 1KB
.settings
org.eclipse.core.resources.prefs 57B
org.eclipse.jdt.core.prefs 177B
src
com
test
a
FlowerView.java 3KB
MainActivity.java 2KB
.project 838B
.classpath 475B
project.properties 361B
AndroidManifest.xml 917B
共 43 条
- 1
资源评论
- an_droid_ch2016-08-10还不错,借鉴了一下
yayun0516
- 粉丝: 2184
- 资源: 59
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功