读书人

起动界面淡入动画显示类

发布时间: 2012-06-29 15:48:47 作者: rapoo

启动界面淡入动画显示类
啥都不要说了,看代码:

/**  *  */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();    }}
直接可以用了

读书人网 >移动开发

热点推荐