• Android彩蛋效果,微信彩蛋效果


    根据Android源码修改,具有微信彩蛋效果

    主要代码

        public static class Board extends FrameLayout {
            public static final boolean FIXED_STARS = true;
    
            // 控制数量
            public static final int NUM_CATS = 30;
    
            static Random sRNG = new Random();
    
            static float lerp(float a, float b, float f) {
                return (b - a) * f + a;
            }
    
            static float randfrange(float a, float b) {
                return lerp(a, b, sRNG.nextFloat());
            }
    
            static int randsign() {
                return sRNG.nextBoolean() ? 1 : -1;
            }
    
            static <E> E pick(E[] array) {
                if (array.length == 0)
                    return null;
                return array[sRNG.nextInt(array.length)];
            }
    
            public class FlyingCat extends ImageView {
                public static final float VMAX = 300.0f;
    
                public static final float VMIN = 100.0f;
    
                public float v, vr;
    
                public float dist;
    
                public float z;
    
                public ComponentName component;
    
                public FlyingCat(Context context, AttributeSet as) {
                    super(context, as);
                    setImageResource(R.drawable.star_anim);
                }
    
                public void reset() {
                    final float scale = lerp(0.5f, 1.5f, z);
                    setScaleX(scale);
                    setScaleY(scale);
                    // setX(-scale * getWidth() + 1);
                    setX(randfrange(0, Board.this.getHeight() - scale * getHeight()));
                    setY(randfrange(0, Board.this.getHeight() - scale * getHeight()));
                    v = lerp(VMIN, VMAX, z);
                    dist = 0;
                }
    
                public void update(float dt) {
                    dist += v * dt;
                    // setX(getX() + v * dt);
                    // 根据Y轴漂移
                    setY(getY() + v * dt);
                }
            }
    
            TimeAnimator mAnim;
    
            Context mContext;
    
            public Board(Context context, AttributeSet as) {
                super(context, as);
                this.mContext = context;
            }
    
            private void reset() {
                removeAllViews();
                final ViewGroup.LayoutParams wrap = new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                for (int i = 0; i < NUM_CATS; i++) {
                    FlyingCat nv = new FlyingCat(getContext(), null);
                    addView(nv, wrap);
                    nv.z = ((float) i / NUM_CATS);
                    nv.z *= nv.z;
                    nv.reset();
                    nv.setX(randfrange(0, Board.this.getWidth()));
                    final AnimationDrawable anim = (AnimationDrawable) nv.getDrawable();
                    postDelayed(new Runnable() {
                        public void run() {
                            anim.start();
                        }
                    }, (int) randfrange(0, 1000));
                }
                if (mAnim != null) {
                    mAnim.cancel();
                }
                mAnim = new TimeAnimator();
                mAnim.setTimeListener(new TimeAnimator.TimeListener() {
                    public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
                        for (int i = 0; i < getChildCount(); i++) {
                            View v = getChildAt(i);
                            if (!(v instanceof FlyingCat))
                                continue;
                            FlyingCat nv = (FlyingCat) v;
                            nv.update(deltaTime / 200f);
                        }
                    }
                });
            }
    
            @Override
            protected void onSizeChanged(int w, int h, int oldw, int oldh) {
                super.onSizeChanged(w, h, oldw, oldh);
                post(new Runnable() {
                    public void run() {
                        reset();
                        mAnim.start();
                    }
                });
            }
    
            @Override
            protected void onDetachedFromWindow() {
                super.onDetachedFromWindow();
                mAnim.cancel();
            }
    
            @Override
            public boolean isOpaque() {
                return true;
            }
        }

     少写了一行,源码下载地址:http://download.csdn.net/detail/zgz345/8247563

  • 相关阅读:
    一起谈.NET技术,WPF 自定义快捷键命令(Command) 狼人:
    一起谈.NET技术,WPF 基础到企业应用系列5——WPF千年轮回2 狼人:
    一起谈.NET技术,asp.net页面中输出变量、Eval数据绑定等总结 狼人:
    单片机沉思录——再谈static
    Java平台对脚本语言支持之ScriptEngine创建方式
    [置顶] [Html] Jquery那些事
    codeforces 165E Compatible Numbers
    2013第六周上机任务【项目2 程序填空(1)】
    腾讯再否认微信收费 三大运营商态度分化
    电子钟程序
  • 原文地址:https://www.cnblogs.com/zgz345/p/4164239.html
Copyright © 2020-2023  润新知