50个Android开发技巧(02 延迟载入和避免反复渲染视图)
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent"
android:layout_height= "fill_parent" > <Button
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_gravity ="center_vertical"
android:onClick ="onShowMap"
android:text ="@string/show_map" /> <include
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_alignParentBottom ="true"
android:layout_marginBottom ="30dp"
layout ="@layout/footer" /> </RelativeLayout>
<TextView xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width= "0dp"
android:layout_height= "0dp"
android:gravity= "center"
android:text= "@string/footer_text" />
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent"
android:layout_height= "fill_parent" > <Button
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_gravity ="center_vertical"
android:onClick ="onShowMap"
android:text ="@string/show_map" /> <include layout ="@layout/footer" /> </RelativeLayout>
<TextView xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent"
android:layout_height= "wrap_content"
android:layout_alignParentBottom= "true"
android:layout_marginBottom= "30dp"
android:gravity= "center"
android:text= "@string/footer_text" />
ViewStub是一个不可见、不占空间(zero-sized)的控件。它能够用来在执行时延迟载入视图资源。仅仅有当我们将ViewStub的可见性设为true。或者调用inflate()方法,它的视图资源才会被载入。
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent"
android:layout_height= "fill_parent" > <Button
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_gravity ="center_vertical"
android:onClick ="onShowMap"
android:text ="@string/show_map" /> <ViewStub
android:id ="@+id/map_stub"
android:layout_width ="fill_parent"
android:layout_height ="fill_parent"
android:inflatedId ="@+id/map_view"
android:layout ="@layout/map" />
</RelativeLayout>
map.xml
<com.google.android.maps.MapView xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent"
android:layout_height= "fill_parent"
android:apiKey= "my_api_key"
android:clickable= "true" />
public class MainActivity extends MapActivity { private View mViewStub; @Override
public void onCreate (Bundle savedInstanceState ) {
super. onCreate( savedInstanceState );
setContentView( R. layout. main);
mViewStub = findViewById( R. id. map_stub);
} public void onShowMap (View v) {
mViewStub. setVisibility (View .VISIBLE );
}
....
}
或许当你仅仅将其应用在一个简单的页面其中时,并不会感觉到在性能上有不论什么提升,可是在复杂页面中,它的效果是极佳的。
50个Android开发技巧(02 延迟载入和避免反复渲染视图)的更多相关文章
- 50个android开发技巧
50个android开发技巧 http://blog.csdn.net/column/details/androidhacks.html
- 50个Android开发技巧(24 处理ListView数据为空的情况)
在移动平台上为用户展示数据的一个经常用法是将数据填充进一个List内,而此时须要注意的一点就是: 原文地址:(http://blog.csdn.net/vector_yi/article/d ...
- 50个Android开发技巧(11 为文字加入特效)
问题:怎样构建一个模拟LED数字时钟的页面?效果例如以下图所看到的: (原文地址:http://blog.csdn.net/vector_yi/article/details/24460227) 分析 ...
- 50一个Android开发技巧(01 利用好layout_weight属性)
问题:如何将一个Button放置在布局的中间,并设置其宽度parent的50%? 分析:问题想要达到的效果应该是这样: (原文地址:http://blog.csdn.net/vector_yi/art ...
- 50个Android开发技巧(03 自己定义ViewGroup)
问题:怎样创建一个例如以下图所看到的的布局? 图1 (原文地址:http://blog.csdn.net/vector_yi/article/details/244155 ...
- 50个Android开发技巧(12 为控件加入圆角边框)
控件的圆角边框能够使你的App看起来更美观,事实上实现起来也非常easy. (原文地址:http://blog.csdn.net/vector_yi/article/details/24463025) ...
- 50个Android开发技巧(09 避免用EditText对日期进行验证)
我们都知道,在表单中对数据进行验证不但无聊并且easy出错. (原文地址:http://blog.csdn.net/vector_yi/article/details/24424713) 想象一下,一 ...
- 50个Android开发技巧(10 为TextView加入样式)
首先来看一个控件的例子: (原文地址:http://blog.csdn.net/vector_yi/article/details/24428085) 手机上类似这种场景你一定已经见过非常多次了,但有 ...
- 50个Android开发人员必备UI效果源码[转载]
50个Android开发人员必备UI效果源码[转载] http://blog.csdn.net/qq1059458376/article/details/8145497 Android 仿微信之主页面 ...
随机推荐
- [LOJ 1030] Discovering Gold
B - Discovering Gold Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- 对 Azure 虚拟网络网关的改进
YU-SHUN WANG Azure 网络高级项目经理 在 2014 年欧洲 TechEd 大会上,我们宣布了对Azure 虚拟网络网关的多项改进: 1. 高性能网关 SKU 2. Azure 虚 ...
- 【转】 实现 Cocos2d-x 全局定时器
转自:http://www.tairan.com/archives/3998 cocos2d-x 中有自己的定时器实现,一般用法是在场景,层等内部实现,定时器的生命周期随着它们的消亡而消亡,就运行周期 ...
- 【转】ubuntu自动挂载硬盘方法
首先建立挂载目录例如:sudo mkdir /movie #根目录下建立movie文件夹sudo mkdir /work #根目录下建立work文件夹 然后查看硬盘信息sudo fdisk -l ...
- javascript-实现日期大写
<script language="javascript"> $(document).ready(function() { //定义中文数组 var chinese = ...
- [Tommas] 测试用例覆盖率(二)
二.详细用例的设计 划分好了测试项,接着就是针对各个测试项,考虑具体的测试用例了.根据测试项的特点,测试用例的设计角度也有所不同.下面我们就来看看通常的功能点测试用例,该从哪些角度出发来进行设计: 1 ...
- appium初探问题总结
自从搭建好环境后,运行一个appdemo各种奇葩问题层出不穷,过后可能觉得是挺简单的问题,但对于初次接触的人来说,有砸电脑的冲动也不为过·这里将自己所遇到的问题记录下来,备忘. 问题一:照着网上的教程 ...
- Msp430概述
总结一下MSP430给我的印象吧,感觉他就是一个迷你型的arm 1:MSP430采用的是精简指令,他只有27条核心的汇编指令,这一点和arm相同,arm同样是采用精简指令,而80c51采用的是冗余指令 ...
- jquery选择器返回值
jquery选择器$('selector')返回的不是数组,而是封装好的jquery对象.但这个对象有一个特别的地方,就是查询到的节点被以下标为属性,添加到了jquery对象上,所以它看起来像数组,因 ...
- 你真的知道HTML吗?
经过几次面试当中,被问及到最基础的东西,没想到回答不上来,有点蛋痛,今天特地的复习了一下!! 内容: 1.Doctype(文档类型)的作用是什么?有多少文档类型? 2.浏览器标准模式和怪异模式之间的区 ...