Android优化——UI优化(四) 使用stytle
2016-02-29 10:26
387 查看
使用style替换背景,防止Activity黑色背景闪过
1.原来的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/img_bg" android:orientation="horizontal"> <Button android:layout_weight="1" android:layout_width="0" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button2"/> <Button android:layout_weight="1" android:layout_width="0" android:layout_height="wrap_content" android:text="New Button1" android:id="@+id/button3"/> </LinearLayout>
这里我们用了
android:background="@drawable/img_bg"来设置了背景图片,但是当我们启动activity是有时候会出现一个黑色的背景,然后才出现我们设置的背景,给用户感觉我们的程序运行的很慢
2.解决办法
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="android:background">@drawable/img_bg</item> </style> </resources>
我们可以给主题设置一个背景,这样就不会给用户感觉我们的应用卡住了
3.知其然知其所以然
1.因为程序的主题是在程序启动的时候加载
2.Layout中设置的背景实在Activity启动之后才加载
所以会让用户看到一个黑色背景闪过的过程。
相关文章推荐
- Android优化——UI优化(三)使用ViewStub延迟加载
- Android优化——UI优化(二) 使用include标签复用布局
- Android优化——UI优化(一)优化布局层次
- UIKit框架(5)控制器的创建
- DicomIoException: Requested 132 bytes past end of fixed length stream.
- 显示队列内容
- poj 2478: Farey Sequence
- 创建 maven maven-archetype-quickstart 项目抱错问题解决方法
- leetcode 304. Range Sum Query 2D - Immutable
- easyui combobox加载内嵌对象赋值
- request.getParameter与request.getParameterNames以及request.getParameterValues的区别
- UIView事件传递
- easyui序号实现累加
- UIKit框架(4)App应用沙盒
- UINavigationController之NavigationItem
- 十七、Uiautomator 快速调试
- UiAutomator的使用过程
- iOS 开发之动画篇 - 从 UIView 动画说起
- MySQL Packet for query is too large
- 引导页和发起页框架简单自定义/LXGuideAndLaunch