有时候你的布局可能需要使用较少的复杂视图。无论它们是项目详情,进度指示器,或者撤销信息,你能通过仅仅在视图被需要的时候加载的方式,来减少内存消耗和加快显示。
——————————————————————————————————————————————————————————————
viewStub是一个没有大小,在布局中不绘制或者不参与的轻量级视图。同样的,它便于在一个视图结构增加或删除。每个ViewStub仅需要包含android:layout属性来指定将被包含的布局。
下面的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" />
——————————————————————————————————————————————————————————————
当你想加载通过ViewStub指定的布局的时候,调用setVisiblity(View.VISIBLE)或者inflate()任一方法让它可见。
((ViewStub) findViewById(R.id.stub_import)).setVisibility(View.VISIBLE);
// or
View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();
注意:inflate()方法返回完成填充的视图。所以如果你需要和这个布局交互,不需要调用findViewById()。
一旦可见/被填充,ViewStub元素不再是这个视图结构的一部分。它被被填充的布局取代,并且这个布局的根视图的ID被ViewStub的android:inflatedid属性指定。(andorid:id属性指定的ViewStub的ID仅仅到ViewStub布局可见/被填充之前有效。)
注意:ViewStub的一个缺点是现在它在布局中不支持<merge/>标识。
分享到:
相关推荐
Android Cookbook: Problems and Solutions for Android Developers by Ian F. Darwin English | 10 May 2017 | ASIN: B071VLZ9ZK | 838 Pages | AZW3 | 12 MB Jump in and build working Android apps with the ...
Manning RxJava for Android Developers Manning RxJava for Android Developers
Kotlin for android developers 中文学习文档 https://leanpub.com/kotlin-for-android-developers 英文版 - Github: https://github.com/wangjiegulu/kotlin-for-android-developers-zh
Kotlin for android developers中文版翻译 Kotlin for android developers中文版翻译
本书介绍Scala基本语法、构造。以及如何将您已经知道的复制java语法转换为Scala,了解Scala除了javabecome之外还提供了哪些功能编程概念和惯用技巧和建议,这些技巧和建议在将现有java项目转换为Scala时非常有用
Linux for Developers: Jumpstart Your Linux Programming Skills (Developer's Library) by William "Bo" Rothwell English | 17 Apr. 2017 | ASIN: B06ZY85CPJ | 224 Pages | AZW3 | 5.37 MB Linux for ...
kotlin for android developers 中文版, kotlin for android developers 中文版
CalendarProvider是用于用户的日历事务的仓库。CalendarProviderAPI允许你在日历,事务,参与者,提醒等,执行查询,插入,更新,和删除操作。CalendarProvderAPI能通过应用程序和同步Adapter被使用。...
《Kotlin for android developers中文版翻译》
Wiley - Java Programming for Android Developers - For Dummies 2nd - 2017
Kotlin-for-Android-Developers:该书的配套应用
Kotlin for android developers(非扫描中文)下载后解压即可,更多请关注我的博客:xiayye5
Kotlin for Android Developers 中文版 ---------------------------------------------------- 本 ePub 基于开源文档,目录书签齐全。 版权归原作者,翻译版权归译者。 ------------------------------------------...
kotlin-for-android-developers-zh 中文版本,请支持正版。 https://leanpub.com/kotlin-for-android-developers
Kotlin for Android Developers - Learn Kotlin the easy way.pdf
kotlin-for-android-developers; kotlin-for-android-developers; kotlin-for-android-developers;
This book is a handy reference for all Android app developers. Table of Contents Chapter 1: Getting Started with Android Chapter 2: Views, Graphics, and Drawing Chapter 3: User Interaction Recipes ...
Master the fundamentals of Scala and understand its emphasis on functional programming that sets it apart from ...Java developers looking to transition to Scala. No prior experience necessary in Scala.