消除 activity 启动时白屏、黑屏问题
2015-07-25 23:05
337 查看
这种问题一般是因为一个Activity启动之后在显示视图之间时间太长导致的。
1、优化方式可以通过精简layout文件、多线程处理数据载入等。
2、但是有些Activity的layout文件可能比较大,如果不能动态载入,在显示之前解析xml的时间可能耗时比较长比如500-1000ms。
这个时候Activity会先显示默认的黑色背景图,所以会出现黑屏的情况。对于这种情况我们可以在Application的Theme中添加
默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中你看到的就是白屏,显然影响用户体验,怎么消除呢?
在 Activity theme 设置style 即可
[html] view
plaincopy
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
[html] view
plaincopy
<application
android:name="com.skymobi.moposns.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.skymobi.moposns.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
1、优化方式可以通过精简layout文件、多线程处理数据载入等。
2、但是有些Activity的layout文件可能比较大,如果不能动态载入,在显示之前解析xml的时间可能耗时比较长比如500-1000ms。
这个时候Activity会先显示默认的黑色背景图,所以会出现黑屏的情况。对于这种情况我们可以在Application的Theme中添加
<item name="android:windowIsTranslucent">true</item>
将默认的窗口背景设置为透明色,这样就不会出现黑屏了。
默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中你看到的就是白屏,显然影响用户体验,怎么消除呢?
在 Activity theme 设置style 即可
[html] view
plaincopy
<style name="AppTheme" parent="android:Theme.Light.NoTitleBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
[html] view
plaincopy
<application
android:name="com.skymobi.moposns.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.skymobi.moposns.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
相关文章推荐
- Centos7安装gitlab
- 基于MFC的socket编程(异步非阻塞通信)
- [C++学习笔记]--位运算、引用、const指针
- CNN卷积神经网络学习笔记4:代码学习
- (详细图解)把SQLServer数据导入Access中
- 最简单的基于FFmpeg的移动端例子附件:SDL Android HelloWorld
- asp.net重写服务器控件
- iOS 多线程GCD 四
- C语言判断用户输入的是字符还是数字
- centos6.5下postgresql9.4.3同步流复制的standby安装与配置
- 编译hadoop-2.5.2的源码过程
- centos6.5下postgresql9.4.3同步流复制的standby安装与配置
- zoj2417 Lowest Bit
- csu 1604 SunnyPig (bfs)
- java IO图
- 在java项目开发中要加入的spring的jar包(以spring 3.1版本为例)
- Xcode7 app 联网问题
- emacs 新手笔记(四) —— 使用 dired 完成一些简单的文件和目录操作
- Swift语言与Objective-C语言混合编程
- 为什么wait(),notify()和notifyAll()必须在同步块或同步方法中调