为自己的APP添加启动页

作者: 小尘哥 | 来源:发表于2017-11-08 22:02 被阅读32次

打开APP的时候会有一个启动过程 ,为了较好的体验,一般加载一个启用页(大部分可能是广告······)。 最熟悉的打开微信时候一个地球图片,这篇文章简单介绍怎么加载该图片。

添加布局文件

解决思路:定义一个linearLayout、设置背景即可。2秒钟后隐藏该界面,加载MainActivity。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/launch"
    >
    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/launchImg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/launch">
    </LinearLayout>
</LinearLayout>

定义启动Activity

设置隐藏时间(2000ms),时间到动画结束时候,隐藏该布局,打开MainActivity

package com.mos.weather;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.LinearLayout;

/**
 * Created by Administrator on 2017/11/5.
 */

public class LaunchActivity extends Activity {
    private LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //加载启动图片
        setContentView(R.layout.activity_launch);
        animationLaunch();
    }
    private void animationLaunch() {
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 1.0f);
        alphaAnimation.setDuration(2000);
        linearLayout = findViewById(R.id.launchImg);
        linearLayout.setAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                linearLayout.setVisibility(View.VISIBLE);
            }
            @Override
            public void onAnimationEnd(Animation animation) {
                linearLayout.setVisibility(View.GONE);  
                Intent intent = new Intent(LaunchActivity.this, MainActivity.class);
                startActivity(intent);
                //结束当前的 Activity
                LaunchActivity.this.finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        }
        );
    }
}

修改默认加载Activity

修改AndroidMenifest.xml中启动时候加载的主Activity为上面定义的LaunchActivity

<activity android:name=".LaunchActivity"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
</activity>

启动图

把准备好的launch.png图片扔到drawable目录下(和上面布局中的路径要对应)即可

启动图

效果图

S71108-214255.jpg

当然,上面可以加“N秒后关闭”,“跳过”等等,这是后话

相关文章

  • 为自己的APP添加启动页

    打开APP的时候会有一个启动过程 ,为了较好的体验,一般加载一个启用页(大部分可能是广告······)。 最熟悉的...

  • iOS 实现有效延时启动页

      目前国内App有这样的需要:在App启动的时候加定时广告,为增加曝光度多显示几秒的启动页。但是系统默认启动页显...

  • 产品经理如何设计APP启动页

    本文大纲:1)APP启动页的设计初衷;2)APP启动页的分类;3)APP启动页的设计方法和原则 1 为什么要做启动...

  • iOS11 适配

    1、启动页 如果启动页采用 Launch Imaged Sourc,则需要添加iPhoneX的启动图,不然整个 A...

  • iOS获取启动图

    获取App启动图的方法 为启动图添加一个动画效果 NSString转NSData NSData转NSString

  • App启动页设计实例和技巧,启动即让人心动

    App启动页,也称闪屏页,最初是为缓解用户等待Web/iOS/Android App数据加载的焦虑情绪而出现,后被...

  • Android 启动页图片与虚拟按键重叠

    通常情况下,我们为了避免 App 启动时的白屏问题,我们会给启动页添加一个 Theme .可能如下: 这个确实避免...

  • iOS_LoadingController

    App 启动的引导页制作,如下步骤 设置 ViewController 的 View 为 ImageView; 添...

  • OC对象原理探究(上)

    APP启动流程探索 创建空工程代码如下,并且添加符号断点命名如下图 运行工程查看堆栈信息 红色为app启动过程: ...

  • app启动页

    今天自己做的小作品准备提交,就差一个启动页,各种百度,各种搜,结果还好最后终于出来了,和大家分享一下,这个过程中遇...

网友评论

    本文标题:为自己的APP添加启动页

    本文链接:https://www.haomeiwen.com/subject/cnkumxtx.html