Android引导页面,停留数秒后跳转到主界面。
loading.xml
<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" >
<ImageView
android:id="@+id/loading_new"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/loading" />
</RelativeLayout>
Loading.java
package com.tax;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
public class Loading extends Activity {
ImageView loading_img;
public static Loading loading_instance = null;
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
loading_instance = this;
setContentView(R.layout.loading);
loading_img = (ImageView) findViewById(R.id.loading_new);
/*
* An animation listener receives notifications from an animation.
* Notifications indicate animation related events, such as the end or
* the repetition of the animation.
*/
AlphaAnimation animation = new AlphaAnimation(1.0f, 1.0f);// 设置透明度(0.0f,
// 1.0f)渐变效果
animation.setDuration(2000);// 设置动画时间毫秒
loading_img.setAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//跳转到主界面
Intent intent = new Intent(Loading.this, MainFragment.class);
startActivity(intent);
}
});
}
}
API资料: Android api链接