您的位置:首页 > 其它

论SplashActivity(一)

2015-12-12 11:12 211 查看

对于这个相信做过项目的都懂,那就让不太懂的了解了解吧

要设置Splash页面,首先想到的是,如何设置全屏问题,直接上代码,下面有两种方法可以使用

The first method

在清单文件(AndroidManifest.xml)中设置

<activity android:name=".SplashActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
</activity>


The second method

在代码(code)中实现

public class SplashActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// No Titlebar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);
// Full Screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

}
}


谨记

(this.requestWindowFeature(Window.FEATURE_NO_TITLE);)

必须在(setContentView(R.layout.activity_splash);)之前

布局文件activity_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
android:id="@+id/rl_root"
tools:context="com.example.admin.zhbj.SplashActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/splash_horse_newyear"/>
</RelativeLayout>


接下来(Following)我们要处理的是设置SplashActivity的动画效果

单个动画设置

RelativeLayout rlRoot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// No Titlebar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);
// Full Screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

rlRoot = (RelativeLayout) findViewById(R.id.rl_root);
startAnim();
}
/**
* 开启动画
*/
private void startAnim() {

//旋转动画
RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(5000);//动画时间
rotate.setFillAfter(true);//保持动画状态
rlRoot.startAnimation(rotate);
}


对于多个动画(animation)问题code如下:

/**
* 开启动画
*/
private void startAnim() {
//动画集合
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(5000);//动画时间
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(5000);//动画时间
scale.setFillAfter(true);//保持动画状态

//渐变动画
AlphaAnimation alp = new AlphaAnimation(0,1);
alp.setDuration(5000);//动画时间
alp.setFillAfter(true);//保持动画状态

set.addAnimation(rotate);
set.addAnimation(scale);
set.addAnimation(alp);

rlRoot.startAnimation(set);
}


动画监听的设置

//设置动画监听
set.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}
//动画结束
@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent(SplashActivity.this, GuideActivity.class));
finish();
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});


传承者(Inheritors)欢迎各位纠正错误,评论,吐槽!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: