Loading Views On Demand

THIS LESSON TEACHES YOU TO

  1. Define a ViewStub
  2. Load the ViewStub Layout

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可推迟加载的更多相关文章

  1. Layout Resource官方教程(3)在layout中用include嵌入其它layout

    简介 <include>Includes a layout file into this layout. 类似 #include ,把layout展开在include处 attribute ...

  2. Layout Resource官方教程(1)简介

    Layout Resource SEE ALSO Layouts A layout resource defines the architecture for the UI in an Activit ...

  3. Layout Resource官方教程(4)<include>与<merge>

    Re-using Layouts with <include/> THIS LESSON TEACHES YOU TO Create a Re-usable Layout Use the ...

  4. Android开发教程 - 使用Data Binding(七)使用BindingAdapter简化图片加载

    本系列目录 使用Data Binding(一)介绍 使用Data Binding(二)集成与配置 使用Data Binding(三)在Activity中的使用 使用Data Binding(四)在Fr ...

  5. 从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用

    标题:从零开始实现ASP.NET Core MVC的插件式开发(六) - 如何加载插件引用. 作者:Lamond Lu 地址:https://www.cnblogs.com/lwqlun/p/1171 ...

  6. img引用网络图片资源无法加载问题解决

    近期在自己项目中遇到引用一些网络图片资源,显示无法加载,但是在浏览器打开图片路径又可以显示的问题 解决办法: 在图片显示的界面把meta referrer标签改为never <meta name ...

  7. 自定义View(7)官方教程:自定义View(含onMeasure),自定义一个Layout(混合组件),重写一个现有组件

    Custom Components In this document The Basic Approach Fully Customized Components Compound Controls ...

  8. Ceisum官方教程2 -- 项目实例(workshop)

    原文地址:https://cesiumjs.org/tutorials/Cesium-Workshop/ 概述 我们很高兴欢迎你加入Cesium社区!为了让你能基于Cesium开发自己的3d 地图项目 ...

  9. Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译

    本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

随机推荐

  1. 基于CAShapeLayer以及UIBezierPath的语音输入效果动画封装

    详情地址 嗯,主要是在简书上写,大家可以关注我的简书,如果有什么更好的建议也可以评论,探讨,加以斧正.

  2. iOS类似QQ好友展开和合并列表的实现代码

    其实原理就是好友列表合上的时候,将这组的cell数设置为0,展开的时候,在变成原来的,就是这么简单 -(); }

  3. asp:get请求写法

    写在前面的话 XMLHttpRequest对象的open方法的第一个参数为request-type,取值可以为get或post.本篇介绍get请求. get请求的目的,主要是为了获取数据.虽然get请 ...

  4. infopath 之绑定列表 数据源

    在psd中启动infopath更新表单模版 注:虽然可能在infopath design中预览的时候会报错说是跨域数据不能加载,别理他 继续发布上站点就不会有这个错误了. 绑定list后效果: 参考u ...

  5. iso和Android的验证码输入框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. java集合_collection子接口 list的特有方法,ArrayList类体现

    /* Collection |--List:元素是有序的,元素可以重复.因为该集合体系有索引. |--ArrayList:底层的数据结构使用的是数组结构.特点:查询速度很快.但是增删稍慢.线程不同步. ...

  7. C++ DLL 获取 MSI Property

    VS2010 创建  C++, Win32 DLL工程C-TEST. Stdafx.h中,在<windows.h>之后 添加引用. #include <msi.h> #incl ...

  8. (转)RPC原理详解

    转自:http://www.open-open.com/lib/view/open1425797146897.html RPC功能目标 RPC的主要功能目标是让构建分布式计算(应用)更加容易,在提供强 ...

  9. C# 多线程基础

    多线程 无论您是为具有单个处理器的计算机还是为具有多个处理器的计算机进行开发,您都希望应用程序为用户提供最好的响应性能,即使应用程序当前正在完成其 他工作.要使应用程序能够快速响应用户操作,同时在用户 ...

  10. AngularJS(4)-服务(Service)

    1.$location服务 $location 服务,它可以返回当前页面的 URL 地址 2.$http服务 $http 是 AngularJS 应用中最常用的服务. 服务向服务器发送请求,应用响应服 ...