Android之SplashActivity

要设置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)欢迎各位纠正错误,评论,吐槽!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值