简介:使用view动画(透明度动画,AlphaAnimation)实现启动页面Splash Screen。View动画的四种变化效果对应着Animation的四个子类:TranslateAnimation、ScaleAnimation、RotateAnimation和AlphaAnimation。四种动画可以用xml和代码控制。
一.页面的布局(activity_splash.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white">
<ImageView
android:id="@+id/iv_splash"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"/>
</RelativeLayout>
使用以上布局来显示启动页的图片。
二.activity来展示动画
1.首先创建View对象
View view = getLayoutInflater().inflate(R.layout.activity_splash,null);
2.新建动画,为当前view设置动画
AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);//第一个参数表示起始透明度,第二个参数表示完全不透明
animation.setDuration(1000);//持续时间
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
;// 动画结束后,可以做一些相应操作
}
});
view.setAnimation(animation);
3.为activity设置视图
setContentView(view);