Android启动画面实现
16lz
2021-12-04
在应用程序中经常用到启动画面,会启动一个后台线程为主程序的运行准备资源。
Android要实现启动画面可以这样做:
这是splash.xml布局文件的代码
代码 < LinearLayout
xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_height ="fill_parent" android:layout_width ="fill_parent" android:orientation ="vertical" >
< ImageView android:layout_height ="fill_parent" android:layout_width ="fill_parent" android:scaleType ="fitCenter" android:src ="@drawable/splash" ></ ImageView >
</ LinearLayout >
放一个ImageView加载启动画面图片
SplashActivity作为主视图启动
代码 /** Calledwhentheactivityisfirstcreated. */@Override
public void onCreate(BundlesavedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handlerx = new Handler();
x.postDelayed( new splashhandler(), 2000 );
}
class splashhandler implements Runnable{
public void run(){
startActivity( new Intent(getApplication(),MainActivity. class ));
SplashActivity. this .finish();
}
}
加载后使用Handler的postDelayed方法,2秒后执行跳转到主视图。
更多相关文章
- Android(安卓)核心分析 之八------Android(安卓)启动过程详解
- android activity的生命周期,四种启动模式
- 关于Android不能启动的问题
- Android(安卓)系统启动过程
- Android(安卓)PackageManagerService的启动过程分析
- Android(安卓)模拟器(emulator)无法启动AVD解决方案
- 占位的实现和间接实现从快捷建中启动一个服务
- 打开URL启动android默认浏览器,启动指定浏览器
- Android初级教程启动定时器详解