Android: Tools

作用

xmlns:tools="http://schemas.android.com/tools"

大致有三种主要功能:

(1)xml中的错误处理,减少或者避免黄线提示,让代码更清爽,让编译少报错。

(2)xml预览,可以随心所欲的定制预览视图。

(3)资源压缩,压缩资源文件,降低APK体积。

错误处理属性

1、tools:ignore

让Lint工具(Lint是Android的代码扫描工具)在检查代码时忽略指定的错误。

RTL(Right  To Left)

2、tools:targetApi

同java代码中的@TargetApi注解,指明某个控制只在指定的API及更高的版本中生效,这样,在使用Lint检测时就不会因minSdkVersion低于控件出一的版本而报错。

3、tools:locale

指明resources中元素的语言类型,避免拼写检查或者Lint检查时报错,这两都只是默认的语言类型是英文 es。

xml视图预览相关属性

以下属性在xml中定义之后,只在预览时会展示,正式部署之后并不会展示。

1、tools:xxx替代android:xxx

将view的任意属性值的android前缀替换为tools之后,就可以实现预览效果。以tools为命名空间的属性值只在预览时有效。另外,在预览时,如果同时有tools:xxx和android:xxx,则优先展示tools:xxx的预览效果。

2、tools:context

声明该布局文件默认关联的activity。声明之后会在布局编辑器或者预览界面中开启一些与该activity相关的特性。

3、tools:itemCount

在RecyclerView节点中设置该属性之后,会指定在预览界面中绘制几个条目。

4、tools:layout

声明在预览时将哪个布局文件填充到该Fragment。

5、tools:listitem, tools:listheader, tools:listfooter

声明AdapterView在预览界面中所展示的条目、头布局、脚布局。

6、tools:showIn

声明该布局文件将会被哪个布局通过<include>引用,声明之后,在对应的文件中不要忘了用<include>引用。

7、tools:menu

声明在预览界面中AppBar将展示哪些菜单。

8、tools:minValue, tools:maxValue

为NumberPicker设置预览时的最小值和最大值。

9、tools:openDrawer

在预览界面中将DrawerLayout打开。

10、@tools:sample/*

为View设置占位文本或图片,这其实就是系统设置的一堆字符串和图片资源,当你想设置预览文本或者预览图片时,如果不想自己去定义,直接引用这些系统预置的字符串和图片就可以了。

资源压缩相关属性

开启资源压缩时,在module的build.gradle文件作如下修改:

android {
    buildTypes {
        release {
            shrinkResources true    //开启资源压缩。minifyEnabled 也必须为true,否则编译不通过
            minifyEnabled true     //开启代码混淆/压缩
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

1、tools:shrinkMode

指明构建工具在压缩资源时使用哪种模式。

2、tools:keep

使用资源压缩去除未使用的资源时,该属性将允许你指明哪些资源可以被保留。

3、tools:discard

当使用资源压缩工具去除一些无用资源时,使用该属性可以指一华夏幸福需要手动删除的资源。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
README for preparing SD/MMC/Micro-SD CARD for booting Android Pre-Requesites -------------- 1) Need to have an SD/MMC/Micro-SD card with atleast 2GB of size. 2) The script needs to be invoked from ubuntu linux machine 8.04 or above. 3) User needs to have sudo privileges. What script will do ------------------- The mkmmc-android.sh partitions the MMC/SD card into three partiions namely boot, rootfs and data. The script will then put the boot images on boot partition and extracts the android rootfs-rootfs_*.tar.bz2 to rootfs partition. Finally the script will copy the Media clips to the data partition and START_HERE folder to boot partition. How to invoke the script ------------------------ There are three ways of invoking this script. 1) Command: sudo ./mkmmc-android <device> <MLO> <u-boot.bin> <uImage> <boot.scr> <rootfs tar.bz2 > <Media_Clips> <START_HERE Location> Example: sudo ./mkmmc-android /dev/sdc MLO u-boot.bin uImage boot.scr rootfs.tar.bz2 Media_Clips Details: In this case, the script will take Boot Images (MLO,u-boot.bin, uImage and boot.scr) Root Filesystem tarball, Media Clips and START_HERE folder as arguements. The script will then put the boot images on boot partition, extract the android rootfs-rootfs_*.tar.bz2 to rootfs partition. Finally the script will copy the Media clips to the data partition and START_HERE folder to boot partition. 2) Command: sudo ./mkmmc-android <device> <MLO> <u-boot.bin> <uImage> <boot.scr> <rootfs tar.bz2 > Example: sudo ./mkmmc-android /dev/sdc MLO u-boot.bin uImage boot.scr rootfs.tar.bz2 Details: In this case, the script will take Boot Images (MLO,u-boot.bin, uImage and boot.scr) and Root Filesystem tarball as arguements. The script will then put the boot images on boot partition, extract the android rootfs-rootfs_*.tar.bz2 to rootfs partition. The data partiton will be left empty in this case. 3) Command: sudo ./mkmmc-android.sh <device> Example: sudo ./mkmmc-android.sh /dev/sdc Details: In this case, the script will assume default locations for BootImages, Root Filesystem, Media_Clips and START_HERE. This command is equivalent to the following sudo ./mkmmc-android /dev/sdc Boot_Images/MLO Boot_Images/u-boot.bin Boot_Images/uImage Boot_Images/boot.scr Filesystem/rootfs.tar.bz2 Media_Clips START_HERE If you are in a particular Board Specific Directory, extracted from DevKit Release, then you can prepare the sd card by executing sudo ./mkmmc-android.sh <device>, to prepare sd card.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值