启动界面淡入动画显示类

啥都不要说了,看代码:

/**
*
*/
package com.lurencun.android.util;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;

import android.os.Handler;
import android.view.animation.AlphaAnimation;
import android.widget.ImageView;

/**
* @author chenyoca [桥下一粒砂] (chenyoca@163.com)
* @data 2011-12-7
* @desc 用于启动界面显示渐变动画的类。
*/
public class TweeningAnimation {
private ImageView splashImgView = null;
private final static String RESOURCE_ID_KEY = "resource_id";
private final static String RESOURCE_TIME_KEY = "show_time";
private final static String RESOURCE_ALAPHA_KEY = "start_alaph";
private final static long DURATION = 1000;
private Queue<Map<String,Integer>> resource_list = new LinkedList<Map<String,Integer>>();

public TweeningAnimation(ImageView view){
splashImgView = view;
}

/**
* 添加一个动画资源
* @param resource_id 资源ID
* @param show_time 显示时间(ms)
* @param start_alaph 起始透明度(0 - 10)
*/
public void addAnimation(int resource_id,int show_time,int start_alaph){
Map<String,Integer> item = new HashMap<String, Integer>();
item.put(RESOURCE_ALAPHA_KEY, start_alaph);
item.put(RESOURCE_TIME_KEY, show_time);
item.put(RESOURCE_ID_KEY, resource_id);
resource_list.add(item);
}

/**
* 显示动画
*/
public void showAnimation(){
int _show_time = 0;
for(Map<String,Integer> item : resource_list){
final int _resource_id = item.get(RESOURCE_ID_KEY);
float alapha = (float) (Math.max(0, Math.min(item.get(RESOURCE_ALAPHA_KEY), 10)) / 10.0);
_show_time += item.get(RESOURCE_TIME_KEY);
final AlphaAnimation animation = new AlphaAnimation(alapha, 1.0f);
animation.setDuration(DURATION);
new Handler().postDelayed(new Runnable(){
@Override public void run() {
splashImgView.setImageResource(_resource_id);
splashImgView.startAnimation(animation);
}
},_show_time);
}
}
}

//例子:

package com.lurencun.android.util;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class DownloadActivity extends Activity {
/** Called when the activity is first created. */
private TweeningAnimation tween;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView v = (ImageView)findViewById(R.id.splash);
tween = new TweeningAnimation(v);
tween.addAnimation(R.drawable.cfuture_logo_320dpi, 2000, 2);
tween.addAnimation(R.drawable.lurencun_logo_320dpi, 3000, 2);
tween.addAnimation(R.drawable.splash, 3000, 2);
}
@Override
protected void onStart() {
super.onStart();
tween.showAnimation();
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值