android UI 优化系之 使用theme 预加载
来源:互联网 发布:hdmi 网络中控 编辑:程序博客网 时间:2024/06/06 02:55
在很多时候,我们需要给一个Layout设置一个背景。例如,我们下下面的layout中使用了这样一个背景:
其中的LinearLayout使用了 背景图片antelope_canyon。整个程序的运行效果如下图:
仔细观察程序的运行过过程,我们首先看到了黑色的activity背景,然后才看到背景图被加载,那是因为在activity start以后,我们才能调用setContentView设置我们的layout,然后才绘制我们在layout中放置的背景图。而在此之前,程序中绘制的是android中默认黑色背景。
这样会给用户感觉我们的activity启动较慢。
然而,如果将背景图定义在一个主题中,如下:
然后在activity中使用这个主题
运行程序,可以看到背景图马上显示了,没有再看到黑色的背景图。
为什么会有这样的现象呢?那是因为 程序的主题是在程序启动的时候加载的,而不是在activity启动之后加载!
而如果在layout使用背景,背景图是在activity启动之后才加载,故而会让用户看到一个黑色背景闪动的过程。
复制代码
- <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/antelope_canyon">
<TextView android:text="@+id/TextView01"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
其中的LinearLayout使用了 背景图片antelope_canyon。整个程序的运行效果如下图:
仔细观察程序的运行过过程,我们首先看到了黑色的activity背景,然后才看到背景图被加载,那是因为在activity start以后,我们才能调用setContentView设置我们的layout,然后才绘制我们在layout中放置的背景图。而在此之前,程序中绘制的是android中默认黑色背景。
这样会给用户感觉我们的activity启动较慢。
然而,如果将背景图定义在一个主题中,如下:
复制代码
- <?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Droidus" parent="android:Theme">
<item name="android:windowBackground">@drawable/antelope_canyon</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
然后在activity中使用这个主题
复制代码
- <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.droidus"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SpeedUpStartupActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Droidus"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
运行程序,可以看到背景图马上显示了,没有再看到黑色的背景图。
为什么会有这样的现象呢?那是因为 程序的主题是在程序启动的时候加载的,而不是在activity启动之后加载!
而如果在layout使用背景,背景图是在activity启动之后才加载,故而会让用户看到一个黑色背景闪动的过程。
- android UI 优化系之 使用theme 预加载
- android UI 优化系之 使用theme 预加载
- android UI 优化系之 使用theme 预加载
- Android UI 优化-使用theme 预加载
- Android UI 优化-使用theme 预加载
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- android UI进阶之style和theme的使用
- android ui 之 Styles 和 Theme
- Android UI优化之HierarchyViewer的使用
- android UI 优化之<viewstub>实现View的延迟加载
- android优化之UI优化
- 【Android UI】theme style
- 值类型和引用类型
- nginx安装配置
- JS语法字典
- 我所知道的.NET异步
- 【Google官方教程】第四课:在UI中显示Bitmap
- android UI 优化系之 使用theme 预加载
- [转]Quartz 2D编程指南(5) – 变换
- 数字签名和数字证书图解
- sort,linux,shell命令
- PNG图像文件结构解析
- 分页的核心思想
- UBuntu下载编译安装内核
- asp.net 使用ajax分页
- MFC画线,要多点一下鼠标,线才出现