这种问题一般是因为一个Activity启动之后在显示视图之间时间太长导致的。
1、优化方式可以通过精简layout文件、多线程处理数据载入等。
2、但是有些Activity的layout文件可能比较大,如果不能动态载入,在显示之前解析xml的时间可能耗时比较长比如500-1000ms。
这个时候Activity会先显示默认的黑色背景图,所以会出现黑屏的情况。对于这种情况我们可以在Application的Theme中添加
<item name="android:windowIsTranslucent">true</item>
将默认的窗口背景设置为透明色,这样就不会出现黑屏了。
默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中你看到的就是白屏,显然影响用户体验,怎么消除呢?
在 Activity theme 设置style 即可
- <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>
- <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>
-