zoukankan      html  css  js  c++  java
  • 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放入消息队列。

  • 相关阅读:
    Java中String的intern方法
    3.7测试复盘
    3.6测试复盘
    LTMU论文解析
    移动机器人相机模型:从相机移动到二维图像
    一步步分析MIPS数据通路(单周期)
    Slam笔记I
    如何理解SiamRPN++?
    如何使用Pytorch迅速写一个Mnist数据分类器
    PySide2的This application failed to start because no Qt platform plugin could be initialized解决方式
  • 原文地址:https://www.cnblogs.com/moka/p/3097338.html
Copyright © 2011-2022 走看看