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 仿微信之主页面 ...
随机推荐
- [POJ 2356] Find a multiple
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6535 Accepted: 2849 ...
- 利用icepdf将pdf文件转为图片
所需jar 包为icepdf-core.jar.icepdf-extra.jar.icepdf-pro-intl.jar.icepdf-pro.jar和icepdf-viewer.jar. 示例代码如 ...
- ejabberd源码流程梳理
ejabberd的工程主要通过ejabberd.app 组织起来 ejabberd.erl : application:start(ejabberd). ejabberd_app.erl: Mod:s ...
- 在windows10+word2010中完美使用北大方正word公式输入法总结
如果在安装输入法时遇到了无法安装的情况,请首先百度下VC运行库安装下(32位64位都安就是),然后安装北大方正word公式输入法,此时不会再提示无法安装,接着(关键)在word应用程序图标右键-> ...
- POJ3279 Fliptile 枚举+简单搜索
题意:一个矩阵,每个点1或0,然后每次翻一个点,它周围上下左右(包括自己)1->0,0->1,问最少翻几次可以矩阵全是0,忽略题目说的字典序 分析:枚举第一行所有的情况,然后下面几行也随之 ...
- 树莓PI上跑爬虫
主要是进行主机上使用myeclipse开发后,在从机上跑最后的程序 在主机上和树莓上都安装好java环境,maven,ant 拷到RPI上的时候修改
- EF5.0修改实体的时候,出现“对一个或多个实体的验证失败。有关详细信息,请参见“EntityValidationErrors”属性这个错误
对于这个错误,要在SaveChanges前关闭验证实体有效性(ValidateOnSaveEnabled)这个开关 db.Configuration.ValidateOnSaveEnabled = f ...
- bzoj 1833 [ZJOI2010]count 数字计数(数位DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1833 [题意] 统计[a,b]区间内各数位出现的次数. [思路] 设f[i][j][k ...
- 【暑假】[实用数据结构]UVAlive 3942 Remember the Word
UVAlive 3942 Remember the Word 题目: Remember the Word Time Limit: 3000MS Memory Limit: Unknown ...
- HDU4614 Vases and Flowers
http://acm.hdu.edu.cn/showproblem.php?pid=4614 HDU 4614 Vases and Flowers (2013多校第二场线段树) // #pragma ...