Android 欢迎界面的制作
0x00Activity
import java.util.TimerTask;
import com.tjrac.R;
import com.tjrac.activity._0.LoginActivity;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
public class WelcomeActivity extends Activity {
private ImageView mShowPicture = null;// 显示图片
private Animation mFadeIn = null;// 开始动画
private Animation mFadeOut = null;// 开始动画
private Drawable mPicture_1 = null;// 第一张图片
private Drawable mPicture_2 = null;
private ImageView mShowtext = null;;
@Override
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_activity);
// 绑定界面
mShowPicture = (ImageView) findViewById(R.id.guide_picture);
mShowtext = (ImageView) findViewById(R.id.guide_text);
// 初始化图片资源
mPicture_1 = getResources().getDrawable(R.drawable.ic_launcher);
// 设置开始界面效果
mShowPicture.setImageDrawable(mPicture_1);
Animation anim = AnimationUtils.loadAnimation(this, R.anim.mshowpicture);
anim.setFillAfter(true);
mShowPicture.startAnimation(anim);
mPicture_2 = getResources().getDrawable(R.drawable.pac_bg_text3);
mShowtext.setImageDrawable(mPicture_2);
mShowtext.setVisibility(View.GONE);
mFadeIn = AnimationUtils.loadAnimation(this,R.anim.guide_welcome_fade_in);
mFadeIn.setDuration(1500L);
// 初始化动画
Handler handler = new Handler();
TimerTask task = new TimerTask() {
@Override
public void run() {
// 隐藏掉全屏图片
mShowtext.setVisibility(View.VISIBLE);
mShowtext.startAnimation(mFadeIn);
}
};
// 5秒后执行TimerTask任务
handler.postDelayed(task, 1500);
// 设置动画的监听
mFadeIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// 第一个动画结束时开始第二个动画
startActivity(new Intent(WelcomeActivity.this,LoginActivity.class));
finish();
}
});
}
}
0x01 布局文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/color_white" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/guide_picture"
android:layout_width="120.0dip"
android:layout_height="120.0dip"
android:layout_centerHorizontal="true"
android:layout_marginTop="200.0dip"
android:scaleType="fitXY" />
<ImageView
android:id="@+id/guide_text"
android:layout_width="250.0dip"
android:layout_height="30.0dip"
android:layout_centerHorizontal="true"
android:layout_below="@id/guide_picture"
android:layout_marginTop="30.0dip"
android:scaleType="fitXY" />
</RelativeLayout>
</FrameLayout>
0x02动画anim
guide_welcome_fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
mshowpicture.xml
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<translate android:fromYDelta="0" android:toYDelta="-100" android:duration="1500" />
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1500"/>
</set>