• Android之一个简单的Activity启动画面


    一般进入一个App都会有一个启动画面,此时后台可以加载一些耗时的资源,同时一个好的启动画面也会让用户觉得很舒服。

    下面我们就来实现一个最简单的启动画面。

    一个启动画面实际上就是一个Activity,到了一定时间之后finish掉并跳转到主Activity,所以我们先来写启动Activity的布局文件:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
    
        <ImageView 
            android:id="@+id/launchImageView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/pic_splash"
             />
    
    </LinearLayout>

    非常简单,就一个ImageView,用来存放我们想要呈现的图片

    然后编写启动Activity:

    public class LaunchScreenActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getWindow().setFormat(PixelFormat.RGBA_8888);
            setContentView(R.layout.launch_layout);
    
            new Handler().postDelayed(new Runnable() {
                public void run() {
                    /* 启动加载画面 */
                    Intent launchIntent = new Intent(LaunchScreenActivity.this, FunctionChoosedActivity.class);
                    LaunchScreenActivity.this.startActivity(launchIntent);
                    LaunchScreenActivity.this.finish();
                }
            }, 2300); //2900 for release
        }
    
    }

    其实就是使用Handler类的postDelay方法延时跳转到主Activity。

    注意使用postDelay方法不会新开线程,只是在当前线程下将Runnable放入消息队列。

  • 相关阅读:
    python:JSON的两种常用编解码方式实例解析
    Python中的map与reduce函数简介
    Python初学者的几个迷惑点
    Python Numpy中数据的常用的保存与读取方法
    python全栈 day03 操作系统 -- 摘要
    python全栈 day02 计算机原理 -- 硬件
    Python作业之购物商城
    Lesson one of python
    总体设计
    ASP.Net页面上用户控件相互调用的方法
  • 原文地址:https://www.cnblogs.com/moka/p/3097338.html
Copyright © 2020-2023  润新知