App启动动画(Splash篇)

来源:互联网 发布:联通网络优化中心 编辑:程序博客网 时间:2024/05/29 16:24

App启动动画(Splash篇)


  • App启动动画Splash篇
    • 简要说明
  • 点此下载源码httpdownloadcsdnnetdetailu0132557379603123

简要说明

本文主要介绍如何写一个Android App 启动动画的一种方式– Splash。这种方式非常简单,话不多说,直接上代码。

1.代码如下:

activity_splash.xml

    <?xml version="1.0" encoding="utf-8"?>    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <ImageView android:id="@+id/loadImage"              <!-- guide为启动动画的图片资源,自己随便找一张就行-->              android:src="@drawable/guide"               android:layout_width="match_parent"               android:layout_height="match_parent" />"    </LinearLayout>

SplashActivity.java

    package com.example.loading.splash;    import com.example.loading.R;    import com.example.loading.Succes.SuccessLaunchActivity;    import com.example.loading.Util.AnimationUtil;    import com.example.loading.tools.Tools;    import com.example.loading.viewPager.ViewPagerActivity;    import android.app.Activity;    import android.content.Intent;    import android.os.Bundle;    import android.view.animation.AlphaAnimation;    import android.view.animation.Animation;    import android.view.animation.Animation.AnimationListener;    import android.widget.ImageView;    public class SplashActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_splash);        ImageView imageView = (ImageView) findViewById(R.id.loadImage);        // 设置加载动画透明度渐变从(0.1不显示-1.0完全显示)        AlphaAnimation animation = new AlphaAnimation(0.1f, 1.0f);        // 设置动画时间5s        animation.setDuration(500);        // 将组件与动画关联        imageView.setAnimation(animation);        animation.setAnimationListener(new AnimationListener() {            // 动画开始时执行            public void onAnimationStart(Animation animation) {                // TODO Auto-generated method stub                // 初始化                init();            }            // 动画重复时执行            public void onAnimationRepeat(Animation animation) {                // TODO Auto-generated method stub            }            // 动画结束时执行            public void onAnimationEnd(Animation animation) {                Intent intent = new Intent(SplashActivity.this, ViewPagerActivity.class);                startActivity(intent);            }        });    }    protected void init() {        // TODO 自动生成的方法存根        Tools.checkNetwork(SplashActivity.this);    }    }

不懂得可以加QQ:793581461 或者在下面评论,尽量及时回答。

点此下载源码:http://download.csdn.net/detail/u013255737/9603123

1 0
原创粉丝点击