您的位置:首页 > 移动开发 > Android开发

android应用启动加载动画页面

2014-11-27 10:18 555 查看
1、当你打开一个应用程序时,会看到前面有一个加载动画页面,看看怎么来实现 

2、新建一个.xml 文件,添加一个ImageView 组件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  

    xmlns:tools="http://schemas.android.com/tools"  

    android:layout_width="match_parent"  

    android:layout_height="match_parent"  

    tools:context=".MainActivity" >  

  

    <ImageView   

        android:id="@+id/welcome_img"  

        android:layout_width="match_parent"  

        android:layout_height="match_parent"  

        />  

  

</RelativeLayout>

3、创建一个Activity

package com.example.activity;  

  

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 MainActivity extends Activity {  

    private ImageView welcomeImg = null;  

  

    @Override  

    protected void onCreate(Bundle savedInstanceState) {  

        super.onCreate(savedInstanceState);  

        setContentView(R.layout.activity_main);  

        welcomeImg = (ImageView) this.findViewById(R.id.welcome_img);  

        AlphaAnimation anima = new AlphaAnimation(0.3f, 1.0f);  

        anima.setDuration(3000);// 设置动画显示时间  

        welcomeImg.startAnimation(anima);  

        anima.setAnimationListener(new AnimationImpl());  

  

    }  

  

    private class AnimationImpl implements AnimationListener {  

  

        @Override  

        public void onAnimationStart(Animation animation) {  

            welcomeImg.setBackgroundResource(R.drawable.welcome);  

        }  

  

        @Override  

        public void onAnimationEnd(Animation animation) {  

            skip(); // 动画结束后跳转到别的页面  

        }  

  

        @Override  

        public void onAnimationRepeat(Animation animation) {  

  

        }  

  

    }  

  

    private void skip() {  

        startActivity(new Intent(this, OtherActivity.class));  

        finish();  

    }  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: