位置: 编程技术 - 正文

Android - Designtime Layout Attributes & Tools Attributes

编辑:rootadmin
Designtime Layout AttributesAs of Android Studio 0.2., the layout rendering (used in both the layout editor as well as the XML editor layout preview window), supports designtime layout attributes.These are attributes which are used when the layout is rendered in the tool, but have no impact on the runtime. This is useful if you for example want to put sample data in your textfields for when you are editing the layout, but you don't want those attributes to affect your running app.To use designtime attributes, first make sure you have the tools namespace defined in your layout:<LinearLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" ...The tools namespace is a specially recognized namespace by the Android tools, so all the attributes you define on view elements in the tools-namespace will be automatically stripped when the application is packaged and there is no runtime overhead.Then, to for example set the text of a text field, use the same attribute as you would from the Android framework, but use the tools: namespace rather than the android: namespace: <TextView android:text="Name:" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText tools:text="John Doe" android:layout_width="wrap_content" android:layout_height="wrap_content" />In the above, the Name label is using the normal text attribute, and will be shown at runtime. However, the text field is using a designtime attribute, so it will appear in the tool, but not at runtime. In general, you can set any Android framework attribute as a designtime attribute; just use the tools: namespace rather than the android: namespace. Note also that you don't have to choose either/or; you can set both the Android namespace attribute (which will be used at runtime) and a tools attribute (which will override the runtime attribute at designtime only).You can also use designtime attributes to unset an attribute while in the tools. For example, there is a bug ( that you cannot use the fastScrollAlwaysVisible attribute on ListViews in the layout editor. However, you may still want that attribute set at runtime. With designtime attributes you can work around it like this: <ListView android:id="@&#;id/listView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:fastScrollAlwaysVisible="true" tools:fastScrollAlwaysVisible=""/>Here's another example; we have a FrameLayout with multiple children, and at designtime we only want to see one of them, let's say the second child: We can use the tools:visibility attribute: <Button android:id="@&#;id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First" tools:visibility="invisible" /> <Button android:id="@&#;id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second" tools:visibility="visible" />(Instead of visibility="invisible" you may want to use visibility="gone", depending on your needs.)LimitationsCurrently only overriding existing attributes is supported. We may want to define some additional convenience attributes to make it simple to for example choose which child in a ViewFlipper to show etc.You have to manually edit in your designtime attributes at this timeThey do not appear as an option in for example the layout editor property sheet. Editor code completion does not help you enter these attributes; the easiest way to use them is to first enter them in the Android namespace, and when done replacing the prefix.Note that designtime attributes are supported only for layout files themselves. You cannot use them anywhere else -- in menu XML files, in string resource definitions, etc.Designtime attributes can only be used for framework resources, not custom attributes at this point.See for background or additional requests or commentsTools AttributesAndroid has a dedicated XML namespace intended for tools to be able to record information in XML files, and have that information stripped when the application is packaged such that there is no runtime or download size penalty. The namespace URI and is usually bound to the tools: prefix:<FrameLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" > ....This document records our current uses of tools attributes. (NOTE: These may change over time.)tools:ignoreThis attribute can be set on any XML element, and is a comma separated list of lint issue ID's that should be ignored on this element or any of its children, recursively.<string name="show_all_apps" tools:ignore="MissingTranslation">All</string>Used by: Linttools:targetApiThis attribute is like the @TargetApi annotation in Java classes: it lets you specify an API level, either as an integer or as code name, that this element is known to be running on. <GridLayout tools:targetApi="ICE_CREAM_SANDWICH" >Used by: Linttools:localeThis attribute can be set on the root element in a resource value file and should correspond to a language and optionally a region. This will let tools know what language (locale) the strings in the file are assumed to be. For example, values/strings.xml can have this root element:<resources xmlns:tools=" tools:locale="es">Now we know that the language used for strings in the default values folder is Spanish rather than English.Used by: Lint, Studio (to disable spell checking in non-English resource files)tools:contextThis attribute is typically set on the root element in a layout XML file, and records which activity the layout is associated with (at designtime, since obviously a layout can be used by more than one layout). This will for example be used by the layout editor to guess a default theme, since themes are defined in the Manifest and are associated with activities, not layouts. You can use the same dot prefix as in manifests to just specify the activity class without the full application package name as a prefix.<android.support.v7.widget.GridLayout xmlns:android=" xmlns:tools=" tools:context=".MainActivity" ... >Used by: Layout editors in Studio & Eclipse, Linttools:layoutThis attribute is typically set in a <fragment> tag and is used to record which layout you want to see rendered at designtime (at runtime, this will be determined by the actions of the fragment class listed by the tag).<fragment android:name="com.example.master.ItemListFragment" tools:layout="@android:layout/list_content" />Used by: Layout editors in Studio & Eclipsetools:listitem / listheader / listfooterThese attributes can be used on a <ListView> (or other AdapterView children like <GridView>, <ExpandableListView> etc) to specify layouts to use for the list items, as well as list headers and list footers, at designtime. The tool will fill in dummy data to show a list with some representative contents. <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" tools:listitem="@android:layout/simple_list_item_2" />Used by: Layout editors in Studio & Eclipsetools:showInAttribute set on the root element of a layout that <include>'ed by another layout. This allows you to point to one of the layouts which includes this layout, and at designtime this included layout will be rendered with the outer layout surrounding it. That allows you to view and edit the layout "in context". Requires Studio 0.5.8 or later. More information in the release announcement.<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android=" xmlns:tools=" android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:showIn="@layout/activity_main" />Used by: Layout editor in Studiotools:menuAttribute set on the root element of a layout to configure the menus to be shown in the Action Bar. Android Studio tries to figure out which menus to use in the ActionBar by looking at the onCreateOptionsMenu() method in the activity linked to the layout (by tools:context). This allows you to override that search and explicitly state which menus to show. The value is a comma separated list of ids (without @id/ or any such prefix). You can also use the file names of the menu xml without the .xml extension. Requires Studio 0.8.0 or later.<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" xmlns:tools=" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:menu="menu1,menu2" />Used by: Layout editor in Studiotools:actionBarNavModeAttribute set on the root element of a layout to configure the navigation mode used by the Action Bar. Possible values include: "standard", "list" and "tabs" Requires Studio 0.8.0 or later.<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" xmlns:tools=" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:actionBarNavMode="tabs" />Used by: Layout editor in Studioref1:

推荐整理分享Android - Designtime Layout Attributes & Tools Attributes,希望有所帮助,仅作参考,欢迎阅读内容。

Android - Designtime Layout Attributes & Tools Attributes

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

Android异常 本文重在Java中异常机制的一些概念。写本文的目的在于方便我很长时间后若是忘了这些东西可以通过这篇文章迅速回忆起来。1.异常机制1.1异常机制是

FrameLayout(框架布局) 框架布局是最简单的布局形式。所有添加到这个布局中的视图都以层叠的方式显示。第一个添加的控件被放在最底层,最后一个添加到框架布局中的视

android 画画板 importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importandroid.net.Uri;importandroid.os.Bundle;importandroid.os.Environment;importandroid.app.Activity;importandroi

标签: Android - Designtime Layout Attributes & Tools Attributes

本文链接地址:https://www.jiuchutong.com/biancheng/376533.html 转载请保留说明!

上一篇:Android 手机影音 学习过程记录(三)(安卓版影音播放器哪个好用)

下一篇:Android异常(Android异常重启保护机制)

  • 收到退个税手续费要交增值税吗?
  • 资产损失税前扣除及纳税调整明细表
  • 发票货物名称前带星号规定
  • 免税农产品发票怎么抵扣申报
  • 电子商业汇票怎么兑现
  • 财务毛利率是毛利率吗
  • 机票抵扣怎么填申报表
  • 所得税纳税申报表在哪里打印
  • 外资企业变内资流程
  • 独资企业是向地税申报个税吗
  • 往来账审计存在问题及建议
  • 门诊药房主要业务
  • 返利平台可信吗
  • 会计科目的使用说明应包括
  • 公司团建收取员工费用
  • 会计增长知识方面
  • 工资哪些扣款应该扣税
  • 一般纳税人企业所得税政策最新2023税率
  • 小规模纳税人普票可以开3%吗
  • 增值税发票如何读入金税盘
  • 住房公积金是全部提取还是留一部分
  • 股权转让企业所得税如何申报
  • 存货发出记账成本最高
  • 同一控制下合并对价怎么算
  • 运输公司造成的损耗
  • 农业生产用水水资源税
  • 房屋租赁收入确认条件新准则
  • 单位价值5000元二手设备怎么算
  • 简易征收办法征收一般纳税人
  • 经营租入的设备计入什么科目
  • PHP:Memcached::setSaslAuthData()的用法_Memcached类
  • 写入缓存策略无法更改
  • 前端常用插件汇总
  • kprcycleaner.exe是什么
  • unity导出webgl报错
  • 固定资产盘盈会影响所有者权益吗
  • 开发支出应属于什么科目
  • 结转损益类收入的分录
  • php输出数字
  • 增值税上期留抵税额
  • 给工程项目买保险是选哪个保险公司
  • 所得税季报本月数是指
  • 前端发起请求怎么设置
  • 其他应付款包括应付股利和应付利息吗
  • 包装费包含什么
  • 扣税的账户是基本户还有一般户
  • 给最爱的他
  • 优先股可转让吗
  • 公司租赁车辆的保险费可以扣除
  • 合伙企业退伙如何缴纳个人所得税
  • 一般纳税人季报还是月报
  • 政府会计财务报表有哪些
  • 计提和支付可以录在一张凭证吗
  • 原材料盘亏属于自然损耗
  • 新公司成立需要刻哪些章
  • 负数发票开票条件?
  • 一般纳税人必须有办公地点吗
  • 注册资本在十年后怎么办
  • 固定资产净残值和净值的区别
  • 建筑行业会计做账流程及会计分录
  • 以前年度损益调整结转到哪里
  • 以设备投资入股的账务处理
  • 以非现金资产抵偿债务
  • 专项拨款会计分录
  • 坏账准备对资产负债表影响
  • 塑料行业税负率是多少
  • 员工借款计入
  • 销售废旧物资是否缴税 如何账务处理
  • 商品销售成本的计算可以采用逆算成本法,其操作方法是
  • netdrive mac
  • 老毛桃u盘启动盘制作工具怎么安装win10系统 老毛桃u盘安装win10系统图文教程
  • centos7.2安装
  • 时间服务器ip 端口
  • win8怎么设置开始
  • win7无法保存对权限所作的更改
  • angular做app
  • shell if -lt
  • linux用yum
  • 留抵税额过多怎么办
  • 开错发票怎么投诉?
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设