SplashActivity
来源:互联网 发布:js 换行符 编辑:程序博客网 时间:2024/05/21 22:34
刚打开app时候会有一个导航界面,这个界面要怎么实现了,所以android小小小鸟写了此博客,希望以后能拿着就用,废话不多说,上代码:
package com.example.administrator.mydemo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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;
/**
* @author rcy
*里面有旋转,透明,缩放 使用时候可以自定义添加或者删除
*/
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
// 准备三种类型的动画(旋转,透明,缩放),此三个动画需要同时执行
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f);
alphaAnimation.setDuration(2000);
// 参数一:起始角度
// 参数二:结束角度
// 参数三:依赖于那个控件旋转
// 参数四:依赖于控件的那个位置旋转
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotateAnimation.setDuration(2000);
ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
scaleAnimation.setDuration(2000);
// 将上诉的三个动画,合并在一起执行(分享插值器) false 不分享一个插值器 true分享一个插值器
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);
findViewById(R.id.iv_splash).startAnimation(animationSet);
// 对执行的动画做监听,执行完了后,在进入导航界面
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// 一旦动画执行完毕,决定进入导航界面(第一次进入应用),还是进入应用程序的主界面
Boolean isFirst = SharePreUtils.getBoolean(
getApplicationContext(), ConstantValue.ISFIRST, false);
if (!isFirst) {
// 进入导航界面
SharePreUtils.saveBoolean(getApplicationContext(),
ConstantValue.ISFIRST, true);
Intent intent = new Intent(getApplicationContext(),
GuideActivity.class);
startActivity(intent);
} else {
// 进入应用程序主界面
Intent intent = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(intent);
}
finish();
}
});
}
}
布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/ic_launcher"/> <!--这里为了方便我使用安卓自带的图片,使用时候替换自己的图片-->
SharePreUtils.class
package com.example.administrator.mydemo;
import android.content.Context;
import android.content.SharedPreferences;
/**
* @author rcy
*/
public class SharePreUtils {
private static SharedPreferences sp;
public static void saveBoolean(Context ctx,String key,boolean value){
if(sp == null){
sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE);
}
sp.edit().putBoolean(key, value).commit();
}
public static Boolean getBoolean(Context ctx,String key,boolean defValue){
if(sp == null){
sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE);
}
return sp.getBoolean(key, defValue);
}
}
ConstantValue.class
class ConstantValue {
public static final String ISFIRST = "isfirst";
public static final String READ_IDS = "read_ids";
}
上篇,我已经抽取出baseactivity下面我们继承,其他不变;
package com.example.administrator.mydemo;import android.content.Intent;import android.os.Bundle;import android.view.View;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.ImageView;/** * @author rcy */public class SplashActivity extends BaseActivity { private ImageView mIvSplash; private AnimationSet animationSet; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_activity); } @Override public void onClick(View v) { } @Override public int getLayoutId() { return 0; } @Override public void initView() { mIvSplash = (ImageView) findViewById(R.id.iv_splash); } @Override public void initData() { // 准备三种类型的动画(旋转,透明,缩放),此三个动画需要同时执行 AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1.0f); alphaAnimation.setDuration(2000); // 参数一:起始角度 // 参数二:结束角度 // 参数三:依赖于那个控件旋转 // 参数四:依赖于控件的那个位置旋转 RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(2000); ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(2000); // 将上诉的三个动画,合并在一起执行(分享插值器) false 不分享一个插值器 true分享一个插值器 animationSet = new AnimationSet(false); animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(rotateAnimation); animationSet.addAnimation(scaleAnimation); mIvSplash .startAnimation(animationSet); } @Override public void initListener() { } @Override public void commonListener() { // 对执行的动画做监听,执行完了后,在进入导航界面 animationSet.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { // 一旦动画执行完毕,决定进入导航界面(第一次进入应用),还是进入应用程序的主界面 Boolean isFirst = SharePreUtils.getBoolean( getApplicationContext(), ConstantValue.ISFIRST, false); if (!isFirst) { // 进入导航界面 SharePreUtils.saveBoolean(getApplicationContext(), ConstantValue.ISFIRST, true); Intent intent = new Intent(getApplicationContext(), GuideActivity.class); startActivity(intent); } else { // 进入应用程序主界面 Intent intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); } finish(); } }); }}就这么简单,本人android小小小鸟,需要学习的还很多,所以只能写成这样,希望大神们不要介意!
阅读全文
0 0
- SplashActivity
- SplashActivity
- SplashActivity 总结
- 动画SplashActivity
- Android之SplashActivity
- 实现启动界面SplashActivity
- 学习笔记-SplashActivity
- android启动界面(SplashActivity)
- SplashActivity的实现
- Android的启动界面-----SplashActivity
- 01SplashActivity界面的完成
- Android手机卫士之SplashActivity
- Android之SplashActivity的巧妙之处
- App应用之启动界面SplashActivity
- App应用之启动界面SplashActivity
- App应用之启动界面SplashActivity
- App启动缓冲界面之SplashActivity
- [android]APP启动界面——SplashActivity
- hdu 2044 一只小蜜蜂 动态规划 简单
- HDU 6140 Hybrid Crystals【阅读题】【水题】
- hdu6134-(莫比乌斯反演)
- 18考研-数据结构复习笔记-线性表03
- java 第一篇 io 相关笔记
- SplashActivity
- 初见bootstrap,iframe框架简单布局
- Non-boring sequences UVA
- B
- socket网络编程(一):最简单的一收一发
- 采购单(京东2017秋招真题)
- react-native坑
- 简单的python网络爬虫实现
- Python-用__slots__限制类属性