No 94 · android 在规定时间内跳转到其他页面
16lz
2021-01-23
在应用程序中经常用到启动画面,会启动一个后台线程为主程序的运行准备资源。
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作为主视图启动
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); Handler x = 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中加载MP4,3gp等视频文件,无法播放问题的解决
- 麦子学院android老师分享android实现listview异步加载图片的方法
- 携程Android App插件化和动态加载实践
- Android异步加载源码示例
- Android Glide加载图片,宽度占满屏幕高度自适应
- 如何正确实现Android启动屏画面的方法(避免白屏)
- android异步加载图片显示,并且对图片进行缓存实例