闪屏页的使用

作为APP程序,为了界面美观,提高用户体验,在进入主界面之前都会有个页面,经常放广告,或者美观的图片,提升用户的评价,让客户喜欢上这款APP,我们称之为闪屏页.

闪屏页的使用

闪屏页使用起来很简单,需要用到handler的一个方法:postDelayed(),里面有2个参数,一个是Runnable接口,一个是延迟执行的时间参数。

闪屏页的布局文件

 <?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"
    android:background="@drawable/ic_launcher_background"
    >


    <LinearLayout
        android:id="@+id/splash"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"

       >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical"
            android:layout_marginBottom="200dp"
          >
            <ImageView
                android:id="@+id/splash_icon"
                android:layout_width="96dp"
                android:layout_height="96dp"


                android:src="@drawable/tu_biao" />
            <TextView
                android:id="@+id/txt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="备忘录"/>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

进入的主界面没内容就只有一个TextView
这里写图片描述

主界面的代码和布局都没用,所以就不粘贴了

闪屏页的代码

package com.example.administrator.csdn_splash;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Splash_activity extends AppCompatActivity {
        protected Handler handler=new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

         handler.postDelayed(new Runnable() {
             @Override
             public void run() {

                 startActivity(new Intent(Splash_activity.this,MainActivity.class));
                 finish();

             }
         },3000);
    }
}

可以看到run方法里直接用Intent跳转到主界面,后面的3000毫秒也就是3秒 代表这个线程延迟3秒执行。

最后的效果就是3秒后跳转主界面

这里写图片描述
这里写图片描述

闪屏页虽然简单,但是应用广泛,用熟练它很重要。

作者:谭健
原文链接: :[点击这里](https://blog.csdn.net/weixin_39028072/article/details/80637987

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值