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)-官 ...
随机推荐
- 12天学好C语言——记录我的C语言学习之路(Day 1)
12天学好C语言--记录我的C语言学习之路 Day 1: 刚刚入门C语言,那么肯定要先把什么是C语言和大家讲清楚,那么大家看下面一段程序(program 1.1): /*//program 1.1 ...
- json转换(c#后台生成json的方法)
此文转自:http://bbs.csdn.net/topics/380200497,为了方便自己记忆才以文章形式保存. using System; using System.Collections.G ...
- asp.net 异步处理
#region 异步测试 //委托 public delegate void PrintDelegate(string s); [WebMethod] public string yibu() { / ...
- warning
warning:statement has no effect [-Wunused-value]| 未能赋值,常见错误:m==1/for(i=0;i++;i<m)/
- AbstractExecutorService (未完成)
AbstractExecutorService是一个实现了ExecutorService的抽象类.主要实现了ExecutorService的invoke方法.
- Android_时间服务
接着上一节,这次我查看了Android的时间服务,觉得帮助很大,解决了我很多疑问,下面我就自己总结了一下,加深了自己的印象,好记性不如烂笔头,还真讲得很不错,收下吧?看下图如何利用线程更新UI组件 重 ...
- php json_encode()和json_decode()
json_encode()和json_decode()分别是编译和反编译过程 注意json只接受utf-8编码的字符,所以json_encode()的参数必须是utf-8编码,否则会得到空字符或者nu ...
- 巧妙使用checkbox制作纯css动态导航栏
前提:很多时候.我们的网页都需要一个垂直的导航栏.可以分类.有分类.自然就有展开.关闭的功能.你还在使用jquery操作dom来制作吗?那你就out了! 方案:使用checkbox 的 checked ...
- [HTML]marquee标签属性详解
请大家先看下面这段代码:<marquee direction=upbehavior=scrollloop=3scrollamount=1 scrolldelay=10align=topbgcol ...
- 响应式布局中重要的meta标签设置.适用于手机浏览器兼容性设置
<!-- #手机浏览器兼容性设置 --> <meta content="application/xhtml+xml;charset=UTF-8" http- ...