Android中文API-ViewStub

ViewStub控件是一个不可见,0尺寸得惰性控件。当ViewStub控件设置可见,或者调用inflate(),并运行完毕之后,ViewStub所指定的layout资源就会被载入。这个ViewStub就会被新载入的layout文件取代。

ViewStub也会从其父控件中移除。

因此ViewStub存在view Hierarchy中的生存期为直到ViewStub运行了setVisable(int)或者inflate()方法。

    在setVisable或者inflate方法运行完成。被载入的Layout文件伴随着ViewStub的属性设置一起被增加ViewStub的父控件中。


    你能够定义或者重写被载入layout文件的id属性。

比如:

<ViewStub android:id="@+id/stub"android:inflatedId="@+id/subTree"android:layout="@layout/mySubTree"android:layout_width="120dip"android:layout_height="40dip" />

    这个定义的ViewStub控件能够通过设定的id“stub”找到。在成功获取subTree制定的kayout之后,ViewStub就从其父控件中移除了,被载入的mySubTree,能够通过id“subTree”找到。从以上的代码属性设置来说,终于载入的Layout文件,会以宽120dp,高40dp展示。

    通过下面方式,能够使ViewStub展示出其所代表的layout文件。


   ViewStub stub = (ViewStub) findViewById(R.id.stub);View inflated = stub.inflate();

当inflate()运行完毕,Viewstub就被替换掉了,inflate返回的View就是mySubTree这个布局文件的View。所以就不须要运行额外的findById了。

    值得注意的是:ViewStub在Api1的时候就已经提供了,可是在api16的时候,添加了一个方法:

public void setLayoutInflater (LayoutInflater inflater)

这种方法攻克了,不能指定LayoutInflater 的问题,这涉及了Context的使用。

    假设你在低于Api16的开发中,遇到找到不你载入View 的 id的情况,那多数情况是。Context出了问题。在低于api16的情况下,解决方案有两种:

(1)自己定义ViewStub

(2)在V7包中。使用ViewStubCompat类。


作者有话说:假设你须要或者Android中文API。请扫一扫以下的二维码,您的关注。就是我的动力。




本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278427.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何播放梅西百货的感恩节大游行2019

Macy’s梅西百货As we draw ever closer to the Thanksgiving holiday, multiple things come to mind: turkey, Black Friday, and the Macy’s Thanksgiving Day Parade. With that in mind, you might want to find a way to stream it for your family. 随着我们越来越接近…

AJAX入门这一篇就够了

什么是Ajax Ajax(Asynchronous JavaScript and XML) 异步JavaScript和XML Ajax实际上是下面这几种技术的融合&#xff1a; (1)XHTML和CSS的基于标准的表示技术(2)DOM进行动态显示和交互(3)XML和XSLT进行数据交换和处理(4)XMLHttpRequest进行异步数据检索(5)Javascript将以上技术…

如何在iPhone和iPad上允许“不受信任的快捷方式”

Khamosh PathakKhamosh PathakShortcuts is now a stock app in iOS 13, iPadOS 13, and beyond. Thanks to Apple’s stricter rules, any shortcut you download from the internet is blocked. Here’s how you can allow untrusted shortcuts on your iPhone or iPad. 现在…

SpringBoot入门 (一) HelloWorld

一 什么是springboot springboot是一个全新的框架&#xff0c;它设计的目的简化spring项目的初始环境的搭建和开发&#xff0c;主要有以下几个特点&#xff1a; 1、简化初始配置 &#xff0c;可与主流框架集成&#xff1b; 2、内置Servlet容器&#xff0c;无需在打War包&#x…

gmail附件调用_如何将Gmail附件保存到Google云端硬盘

gmail附件调用While you can access Gmail attachments by opening the related message deep within Google’s client, it’s not very convenient. You need a central location to access saved documents and images. This guide shows you how to save Gmail attachments…

如何使用VLOOKUP在Google表格中查找数据

VLOOKUP is one of the most misunderstood functions in Google Sheets. It allows you to search through and link together two sets of data in your spreadsheet with a single search value. Here’s how to use it. VLOOKUP是Google表格中最容易被误解的功能之一。 它使…

WPF项目学习.一

WPF项目搭建 版权声明&#xff1a;本文为博主初学经验&#xff0c;未经博主允许不得转载。 一、前言 记录在学习与制作WPF过程中遇到的解决方案。 使用MVVM的优点是 数据和视图分离&#xff0c;双向绑定&#xff0c;低耦合&#xff0c;可重用行&#xff0c;相对独立的设计和逻辑…

airpods_如何通过AirPods与其他人共享音乐

airpodsKhamosh PathakKhamosh PathakUsing the new Audio Sharing feature introduced in iOS 13.1 and iPadOS 13.1, you can share audio from one iPhone with two AirPods. You can watch a video or listen to a song along with your friend in just a tap! 使用iOS 13.…

谷歌云使用账号密码_如何使用Google密码检查

谷歌云使用账号密码Google has a tool designed to securely analyze your passwords against a database of ones that are known to be compromised and breached. Password Checkup is available as an extension or a web service. Here’s how to use it. Google提供了一种…

Jolicloud是一款适合上网本的漂亮新操作系统

Want to breathe new life into your netbook? Here’s a quick look at Jolicloud, a unique new Linux based OS that lets you use your netbook in a whole new way. 想为您的上网本注入新的活力吗&#xff1f; 快速浏览一下Jolicloud&#xff0c;这是一个独特的基于Linu…

Repeater片段

1.字段过长截取字符串 1.1 截取字符串类 可以直接substring 也可以<%# Utility.Common.GetShow( Eval("NewTitle").ToString(),20,true) %><td><%#fcwms.Common.GetContent.GetShow(Eval("com_address").ToString(), 19, true)%> </t…

谷歌浏览器的翻译功能在哪_如何在Google表格中使用AND和OR功能

谷歌浏览器的翻译功能在哪If you’ve ever wanted to check whether data from your Google Sheets spreadsheet meets certain criteria, you can use AND and OR. These logical functions give you TRUE and FALSE responses, which you can use to sort through your data.…

保存网络文章以供以后使用Instapaper阅读

Have you ever come across a bunch of great articles that you want to read online, but just don’t have the time? Today we take a look at an online service that allows you to read your articles later, either online, or on an iPhone, or eReader. 您是否曾经遇…

谷歌chrome xp_将非Google任务列表添加到Chrome

谷歌chrome xpMost people rely on a task list to help them remember what they need to do but not everyone wants one that is tied to a Google account. If you have been wanting an independent tasks list then join us as we look at the Tasks extension for Googl…

我们生活在最好的时代

2019独角兽企业重金招聘Python工程师标准>>> 没规划的人生叫拼图&#xff0c;有规划的人生叫蓝图&#xff1b; 没目标的人生叫流浪&#xff0c;有目标的人生叫航行&#xff01; 我们生活在最好的时代&#xff1a;在认知和学习机会上&#xff0c;人人平等&#xff0c…

MapReduce详解和WordCount模拟

最早接触大数据&#xff0c;常萦绕耳边的一个词「MapReduce」。它到底是什么&#xff0c;能做什么&#xff0c;原理又是什么&#xff1f;且听下文讲解。 是什么 MapReduce 即是一个编程模型&#xff0c;又是一个计算框架&#xff0c;它充分采用了分治的思想&#xff0c;将数据处…

无法创建系统映像_如何创建USB驱动器的映像

无法创建系统映像You can back up your USB drive by creating a saved image. You can then take that saved image and clone multiple USB sticks. This guide shows you how to create an image of your USB drive using Windows 10. 您可以通过创建保存的图像来备份USB驱动…

使用高级管理控制台获得对Windows Home Server的扩展访问

Windows Home Server is easy to setup and use so anyone with basic computer knowledge can operate their own server. But what if you’re an advanced user and want more control over various administrative functions? The Advanced Admin Console Addin gives you…

变动性算法源代码分析与使用示例(copy_backward、 transform、 replace_copy_if 等)

首先回顾前面的文章&#xff0c;我们把for_each 归类为非变动性算法&#xff0c;实际上它也可以算是变动性算法&#xff0c;取决于传入的第三个参数&#xff0c;即函数 指针。如果在函数内对容器元素做了修改&#xff0c;那么就属于变动性算法。 变动性算法源代码分析与使用示例…

如何在Outlook中的电子邮件上显示快速操作按钮

There are probably actions you regularly perform in Outlook, such as deleting, archiving, and marking things as read. Here’s how to use Quick Action buttons to add one-click options that appear over every email to perform each action. 您可能会在Outlook中定…