Android开发之启动页面Splash Screen

来源:互联网 发布:封闭式小区 知乎 编辑:程序博客网 时间:2024/05/16 14:31

简介:使用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() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {;// 动画结束后,可以做一些相应操作}});view.setAnimation(animation);

3.为activity设置视图

setContentView(view);


0 0
原创粉丝点击