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)-官 ...
随机推荐
- selenium文件上传的实现
一.对于上传文件, 从手动操作我们可以看出, 需要对window 窗体进行操作, 而对于selenium webdriver 在这方面应用就受到了限制. 但是, 庆幸的是, 对于含有input ele ...
- EasyUI的DataGrid 分页栏英文改中文解决方案
(一)分页栏英文改中文解决方案 这个问题其实很简单,就是引入文件jquery-easyui-1.3/locale/easyui-lang-zh_CN.js . 注意这个文件要放在本页js的后面,放在最 ...
- as3判断XML是否合法
XML是否合法 在我认为 XML的标签成对 并且根标签外边没有其他东西 以下是合法的 <?xml version="1.0" encoding="utf-8&quo ...
- 调起MT096的配置过程
FTP::cips\/var/cics_regions/RGCIPS/database/PD/PD.RGCIPS|PD.auto 更加新的PD号(其中的路径指向新的程序ibmp),并修改FTP::ci ...
- DBA
一个公司的数据库系统也是由DBA 来进行管理的,它们的主要工作如下: l 安装和配置数据库,创建数据库以及帐户:l 监视数据库系统,保证数据库不宕机:l 收集系统统计和性能信息以便进行调整:l 发现性 ...
- python基础学习(二)--函数
return返回值: python函数都有返回值,函数体内无return,默认返回值None, 函数参数: 1.普通参数 严格按照顺序,将实际参数赋值给形式参数,一一对应. 例: def send(x ...
- 调用windows api 获取系统分辨率
c++中: int cxScreen,cyScreen; cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_CY ...
- .Net 平台下的互联网架构新思考
上一篇<互联网应用架构谈>有很多阅读量,但后来实践中发现基于WCF服务层技术用于实现网站访问的效率是有问题的. 我的本意是以WCF中间层解决商业逻辑,供各个平台调用,然而还是带来诸多的麻烦 ...
- poj 2778 DNA Sequence ac自动机+矩阵快速幂
链接:http://poj.org/problem?id=2778 题意:给定不超过10串,每串长度不超过10的灾难基因:问在之后给定的长度不超过2e9的基因长度中不包含灾难基因的基因有多少中? DN ...
- Oracle表添加主键、外键
1.创建表的同时创建主键约束 (1)无命名 create table student ( studentid int primary key not null, studentname varchar ...