Android的启动界面,制作起来十分容易,我们在使用过程中经常可以看到有个启动效果,通常是一张广告图没加上旋转,缩放和渐变的特效。
更多支持可以访问我的个人网站: https://www.cjluzzl.cn
首先你需要准备一张图,我这里随便找了一张王者荣耀的截图
整个项目的结构图
然后写一个布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/rl_root"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/index"
/>
</RelativeLayout>
回到Activity
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;
public class startFlashActivity extends Activity {
RelativeLayout rlRoot;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startflash);
//找到布局
rlRoot = (RelativeLayout) findViewById(R.id.rl_root);
startFlash();
}
/**
* 开始动画
*/
private void startFlash(){
AnimationSet set = new AnimationSet(false);
//旋转动画设计
RotateAnimation rotate = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f);
rotate.setDuration(2000);
rotate.setFillAfter(true);
//旋转动画设置
ScaleAnimation scale = new ScaleAnimation(0,1,0,1, Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f);
//设置动画持续时间
scale.setDuration(2000);
//是否保持动画结束时的状态
scale.setFillAfter(true);
//渐变色动画设计(透明度变化)
AlphaAnimation alpha = new AlphaAnimation(0,1);
alpha.setDuration(3000);
alpha.setFillAfter(true);
set.addAnimation(rotate);
set.addAnimation(scale);
set.addAnimation(alpha);
//为布局增加动画效果
rlRoot.startAnimation(set);
}
}
为了全屏显示,我们需要在Mainifest文件里把这个Activity的主题设置一下,设置为全屏幕无标题栏的样式
<activity android:name=".startFlashActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这样就完成了一个简单的启动页面制作,效果如图