Layout Resource官方教程(2)用ViewStub引用的嵌入的layout可推迟加载
Loading Views On Demand
THIS LESSON TEACHES YOU TO
YOU SHOULD ALSO READ
Sometimes your layout might require complex views that are rarely used. Whether they are item details, progress indicators, or undo messages, you can reduce memory usage and speed up rendering by loading the views only when they are needed.
用ViewStub引用的嵌入的layout可推迟加载
Define a ViewStub
ViewStub is a lightweight view with no dimension and doesn’t draw anything or participate in the layout. As such, it's cheap to inflate and cheap to leave in a view hierarchy. Each ViewStub simply needs to include the android:layout attribute to specify the layout to inflate.
The following ViewStub is for a translucent progress bar overlay. It should be visible only when new items are being imported into the application.
viewstub示例
<ViewStub
android:id="@+id/stub_import"
android:inflatedId="@+id/panel_import"
android:layout="@layout/progress_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
Load the ViewStub Layout
When you want to load the layout specified by the ViewStub, either set it visible by calling setVisibility(View.VISIBLE) or call inflate().
加载ViewStub对应的layout的2方法
1,((ViewStub) findViewById(R.id.stub_import)).setVisibility(View.VISIBLE);
// or
2,View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();
Note: The inflate() method returns the inflated View once complete. so you don't need to call findViewById() if you need to interact with the layout.
注意 作用第2种方法时,如果该ViewStub对应的lahout是临时的,那么可以不用 findViewById(),
Once visible/inflated, the ViewStub element is no longer part of the view hierarchy. It is replaced by the inflated layout and the ID for the root view of that layout is the one specified by the android:inflatedId attribute of the ViewStub. (The ID android:id specified for the ViewStub is valid only until the ViewStub layout is visible/inflated.)
一旦ViewStub被加载,那么ViewStub就被其指定的layout替换。
Note: One drawback of ViewStub is that it doesn’t currently support the <merge/> tag in the layouts to be inflated.
Layout Resource官方教程(2)用ViewStub引用的嵌入的layout可推迟加载的更多相关文章
- Layout Resource官方教程(3)在layout中用include嵌入其它layout
简介 <include>Includes a layout file into this layout. 类似 #include ,把layout展开在include处 attribute ...
- Layout Resource官方教程(1)简介
Layout Resource SEE ALSO Layouts A layout resource defines the architecture for the UI in an Activit ...
- Layout Resource官方教程(4)<include>与<merge>
Re-using Layouts with <include/> THIS LESSON TEACHES YOU TO Create a Re-usable Layout Use the ...
- Android开发教程 - 使用Data Binding(七)使用BindingAdapter简化图片加载
本系列目录 使用Data Binding(一)介绍 使用Data Binding(二)集成与配置 使用Data Binding(三)在Activity中的使用 使用Data Binding(四)在Fr ...
- 从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用
标题:从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用. 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p/1171 ...
- img引用网络图片资源无法加载问题解决
近期在自己项目中遇到引用一些网络图片资源,显示无法加载,但是在浏览器打开图片路径又可以显示的问题 解决办法: 在图片显示的界面把meta referrer标签改为never <meta name ...
- 自定义View(7)官方教程:自定义View(含onMeasure),自定义一个Layout(混合组件),重写一个现有组件
Custom Components In this document The Basic Approach Fully Customized Components Compound Controls ...
- Ceisum官方教程2 -- 项目实例(workshop)
原文地址:https://cesiumjs.org/tutorials/Cesium-Workshop/ 概述 我们很高兴欢迎你加入Cesium社区!为了让你能基于Cesium开发自己的3d 地图项目 ...
- Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译
本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
随机推荐
- WCF编程系列(三)地址与绑定
WCF编程系列(三)地址与绑定 地址 地址指定了接收消息的位置,WCF中地址以统一资源标识符(URI)的形式指定.URI由通讯协议和位置路径两部分组成,如示例一中的: http://loc ...
- Ext.Net学习笔记16:Ext.Net GridPanel 折叠/展开行
Ext.Net学习笔记16:Ext.Net GridPanel 折叠/展开行 Ext.Net GridPanel的行支持折叠/展开功能,这个功能个人觉得还说很有用处的,尤其是数据中包含图片等内容的时候 ...
- [jquery]高级篇--获取div子元素
参考: http://zhidao.baidu.com/link?url=IfeQQBn1xMLqWvwdkKbQYJ8mC6ciGi_8M1NYkm6iQ-kXBMX2f2ylN-ckzFLiynn ...
- 修改placeholder颜色
#contact_info为textarea的ID #contact_info::-webkit-input-placeholder{ color:#999;}#contact_info:-moz-p ...
- android 文件的权限
- dorado中的creationType选择类型
新建model层中 DataType类型的时候,有几个属性creationType,matchType时候需要在右侧选择对应的javaBean,这是时候要在弹出的对话框搜索. 此时,只要搜索javaB ...
- php header示例代码(推荐)
<?php /*** Function: PHP header() examples (PHP) ** Desc: Some examples on how to use the header( ...
- sql的集合操作
原文转自:http://blog.csdn.net/qsyzb/article/details/12560917 SELECT语句的查询结果是元组的集合,所以多个SELECT语句的结果可进行集合操作. ...
- CSS 神器 compass
compass 官网 compass 算是我在做 前端工程师 中遇到的用的最爽的工具.当我第一次使用它之后就不能自拔.下面对 compass 做一个比较系统的介绍,也可以做一个简单的入门教程.
- 《C和指针》读书笔记——第二章 基本概念
1.编译过程: source code→Compiler→Object code→Linker←Lib ↓ Exe 2.经过初始化的静态变量(static)在程序执行前能获得他们的值. 3.绝大多数环 ...