APP启动界面的实现,第一种方式

最近想把自己在项目中用到的一些功能和看到相关demo整理下,方便以后自己使用和学习,也希望能帮到刚开始开发的朋友,如果在这里有写的不好的地方希望大家帮忙提出和修改。

下面就开始一个简单的APP启动界面的功能实现.:

这是启动的xml文件.

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@null"
        android:scaleType="centerCrop"
        android:src="@mipmap/launch_lina" />

</RelativeLayout></span>
预览图如下所示.
<img src="https://img-blog.csdn.net/20160530165404641?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
在这里我们如果要设置整个图片全屏的话有2种方式。

1:Java文件中在onCreate()方法中使用如下代码可以实现全屏:

public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    //hide the status bar  
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);  
    //hide the title bar  
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
    setContentView(R.layout.main);  
}  
2:或者在 AndroidManifest.xml 中进行配置如下

   android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
如图所示:



下面就是java中的代码了,我在这里使用了一个很简单的方法来实现

使用了android中 AlphaAnimation对象

AlphaAnimation animation = new AlphaAnimation(0.7f ,1.0f);//设置透明度0.7 1.0

整个Activty的代码:

package com.chf.myexerciseapp.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.chf.myexerciseapp.MainActivity;
import com.chf.myexerciseapp.R;

/**
 * Created by chenhf on 2016/5/30.
 */
public class LaunchActivity extends Activity{
    private static final  String TAG = "LaunchActivity";
    private ImageView mImgView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launch);
        mImgView  = (ImageView) findViewById(R.id.img_launch_lina);
        AlphaAnimation animation = new AlphaAnimation(0.7f ,1.0f);//设置透明度0.7 到1.0;
        animation.setDuration(3000);//设置动画持续时间。这里设置的是3秒。
        mImgView.setAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Intent intent  = new Intent();
                intent.setClass(LaunchActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK){
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.ECLAIR) {
                return true;
            } else {
                onBackPressed();
            }
            return true;
        }else {
            return super.onKeyDown(keyCode, event);
        }
    }

    @Override
    public void onBackPressed() {
        Log.d(TAG,"在onBackPressed中拦截返回键");
        return;
    }


}
在上面代码中,我们使用了 setAnimationListener这个方法。该方法所需要传入 AnimationListener这个listener,在改listener的 onAnimationEnd中增加了,跳转到主界面的代码。

一个很简单的启动界面就完成了。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值