Android 简单启动图

作者: 翻身不做咸鱼 | 来源:发表于2016-07-12 03:18 被阅读1314次

    现在市面上很多应用都有启动图。启动图的作用可以介绍应用,也可以给用户进入应用一个缓冲的作用。
    下边看一下简单启动图的效果:



    public class EntryActivity extends Activity {
        @Bind(R.id.iv_entry)
        ImageView mSplashImage;
    
        private static final int ANIMATION_TIME = 2000;
    
        private static final float SCALE_END = 1.13F;
    
        private static final int[] IMAGES = {
                R.drawable.ic_hotbitmapgg,
                R.drawable.splash0,
                R.drawable.splash1,
                R.drawable.splash2,
                R.drawable.splash3,
                R.drawable.splash4,
                R.drawable.splash5,
                R.drawable.splash6,
                R.drawable.splash7,
                R.drawable.splash8,
                R.drawable.splash9,
                R.drawable.splash10,
                R.drawable.splash11,
                R.drawable.splash12,
                R.drawable.splash13,
                R.drawable.splash14,
                R.drawable.splash15,
                R.drawable.splash16,
        };
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_entry);
            ButterKnife.bind(this);
            Random random = new Random(SystemClock.elapsedRealtime());
            mSplashImage.setImageResource(IMAGES[random.nextInt(IMAGES.length)]);
            Observable.timer(1, TimeUnit.SECONDS)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Action1<Long>(){
                        @Override
                        public void call(Long aLong) {
                            startAnim();
                        }
                    });
        }
    
        private void startAnim() {
    
            ObjectAnimator animatorX=ObjectAnimator.ofFloat(mSplashImage,"scaleX",1f,SCALE_END);
            ObjectAnimator animatorY=ObjectAnimator.ofFloat(mSplashImage,"scaleY",1f,SCALE_END);
            AnimatorSet set=new AnimatorSet();
            set.setDuration(ANIMATION_TIME).play(animatorX).with(animatorY);
            set.start();
            set.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
    
                }
    
                @Override
                public void onAnimationEnd(Animator animation) {
                    startActivity(new Intent(EntryActivity.this,MainActivity.class));
                    EntryActivity.this.finish();
    
                }
    
                @Override
                public void onAnimationCancel(Animator animation) {
    
                }
    
                @Override
                public void onAnimationRepeat(Animator animation) {
    
                }
            });
        }
    }
    
    

    1.EntryActivity 不要继承AppCompatActivity,因为AppCompatActivity会去加载主题,导致页面卡顿。
    2.该activity只有一个iamgeview控件。
    3.Observable.timer()Handler定时发送消息,以上代码就是1秒后发送
    4.使用到了ObjectAnimator的缩放,了解ObjeAnimator的更多使用
    5. 一个AnimationSet包含了一系列的Animation,设置时间,设置监听(动画开始,动画结束,动画取消)

    相关文章

      网友评论

        本文标题:Android 简单启动图

        本文链接:https://www.haomeiwen.com/subject/htijjttx.html