基于android的Splash欢迎动画

来源:互联网 发布:php 重复的数据相加 编辑:程序博客网 时间:2024/05/21 14:52

关于Spalash,主要使用的AlphaAnimation来进行设置。这个没什么多说的了,直接上代码吧,是一个比较简单的小功能。

public class SplashActivity extends Activity {    private ImageView logo;    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // 取消标题        this.requestWindowFeature(Window.FEATURE_NO_TITLE);        // 取消状态栏        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                WindowManager.LayoutParams.FLAG_FULLSCREEN);        setContentView(R.layout.activity_splash);        logo = (ImageView) findViewById(R.id.logo);        //创建一个AlphaAnimation对象,0为透明,1为不透明。        AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f);        alphaAnimation.setDuration(3000);        logo.startAnimation(alphaAnimation);        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {            @Override            public void onAnimationStart(Animation animation) {            }            @Override            public void onAnimationRepeat(Animation animation) {            }            @Override            public void onAnimationEnd(Animation animation) {                Intent intent = new Intent();                intent.setClass(SplashActivity.this, LoginActivity.class);                startActivity(intent);                finish();            }        });    }}

然后在Manifest.xml中将Splash这个activity设置成进入程序的入口即可:

<activity android:name=".SplashActivity">    <intent-filter>        <action android:name="android.intent.action.MAIN" />        <category android:name="android.intent.category.LAUNCHER" />    </intent-filter></activity>

完毕,效果不演示了,核心代码就这些了。

0 0
原创粉丝点击