宽度为10个字符的宽度

xml中 android:ems属性 ,作为EditText 默认生成 的属性,其含义是需要编辑的 字符串长度 。
设置为10时,最多编辑 10个em ,一个em单位是 两个inch ,但是随着自动调整,在Android中 em代表‘M’的数量 。
但是 EditText的属性 ,只有在 android:layout_width=“wrap_content” 时,才会显示;
如果是 android:layout_width=“match_parent” 时,则不会有变化。

android:ems

Makes the TextView be exactly this many ems wide.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol ems.

使这个TextView恰好有many个ems宽度。

必须是整数值,如“100”。

这个值可以引用资源(以"@[package:]type:name"的形式)或者包含这个类型的值的主题属性(以"?[package:][type:]name"的形式)

这对应全球资源属性符号ems。

android:maxEms

Makes the TextView be at most this many ems wide.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxEms.

使这个TextView最多可以有many个ems宽度。


实例1:

    <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxEms="4"
android:ems="2"
android:text="一二三四五六七八九十" />
结果:
android:layout_width="match_parent"使得android:maxEms和android:ems无效。

实例2:
    <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="4"
android:text="一二三四五六七八九十" />
结果:

实例3:

    <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="6"
android:text="一二三四五六七八九十" />
结果:

实例4:

    <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="6"
android:maxEms="4"
android:text="一二三四五六七八九十" />
结果:
android:ems覆盖android:maxEms属性。

问题:

    <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="8"
android:text="一二三四五六七八九十" />

结果:正常猜想是显示到8就好了。但结果是显示到了9。

API显示是恰好many个ems宽度。

那这里需要了解一下ems这个单位。

em是一个印刷排版的单位,表示字宽的单位。 em字面意思为:equal M   (和M字符一致的宽度为一个单位)简称em。

ems是em的复数表达。

https://en.wikipedia.org/wiki/Em_%28typography%29

设置为10时,最多编辑 10个em ,一个em单位是 两个inch ,但是随着自动调整(相对单位),在Android中 em代表‘M’的数量 。

结论:该属性是以ems为单位,不是以字符为单位。至于ems和字符之间的关系,还没有了解。正常也很少用这玩意。

android xml 布局文件中 android:ems="10"的更多相关文章

  1. android xml布局文件中tools:layout的作用

    摘要 用最新版本的adt 创建一个基于master/detail flow 模版的app的时候,生成的 activity_item_list.xml 文件中有一个tools:layout属性: fra ...

  2. (转载)Android xml资源文件中@、@android:type、@*、?、@+引用写法含义以及区别

    原帖地址:http://blog.csdn.net/zfrong/article/details/7332545 Android xml资源文件中@.@android:type.@*.?.@+引用写法 ...

  3. Android Fragment之间的通信(用fragment替换掉XML布局文件中的一个线性布局)

    1.XML布局 (1)主界面 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...

  4. 通过在xml布局文件中设置android:onClick=""来实现组件单击事件

    在布局中出现android:onClick=""语句: <Button android:id="@+id/call_button" android:onC ...

  5. Android xml资源文件中@、@android:type、@*、?、@+含义和区别

    一.@代表引用资源 1.引用自定义资源.格式:@[package:]type/name android:text="@string/hello" 2.引用系统资源.格式:@andr ...

  6. 【转】Android xml资源文件中@、@android:type、@*、?、@+含义和区别

    一.@代表引用资源 1.引用自定义资源.格式:@[package:]type/name android:text="@string/hello" 2.引用系统资源.格式:@andr ...

  7. Android:关于声明文件中android:process属性说明

    笔者在学习Android Service组件的过程中碰到了一个问题,就是在Android应用的声明文件Manifest.xml中有时候会对相关的服务标签设置一个android:process=&quo ...

  8. android布局文件中android:icon="?attr/menuIconCamera"找不到对应图标路径

    如 <item android:id="@+id/camera" android:title="Camera" android:icon="?a ...

  9. Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析

    转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PAREN ...

随机推荐

  1. NSIS编译报错:您可能有有一个或两个(大)的旧临时文件

    一.有时在编译NSIS时会出现如下错误: 注意: 您可能有有一个或两个(大)的旧临时文件 残留在临时目录文件夹中 (通常这种情况只会发生在 Windows 9x 系统中). 二.本人遇到的问题原因: ...

  2. 系统编程--高级IO

    1.非阻塞I/O 非阻塞I/O使我们可以调用不会永远阻塞的I/O操作,例如open,read和write.如果这种操作不能完成,则立即出错返回,表示该操作如继续执行将继续阻塞下去.对于一个给定的描述符 ...

  3. maven学习(十七)——在eclipse中导入外部maven项目

    外部maven项目,导入Eclipse中进行开发 操作步骤如下所示:

  4. atom下python好用的几个插件

    atom下python好用的几个插件 atom-beautify 代码优化 atom-python-run 运行 autocomplete-python 代码补全 file-icons 图标优化 hi ...

  5. kvm搭建完成了,那么问题来了,到底是什么原理

    kvm中到底是怎么模拟的CPU和内存? 收到了大量的 这里有一个裸的调用kvm接口的实例,超赞: http://www.cnblogs.com/Bozh/p/5753379.html 使用kvm的AP ...

  6. 【bzoj4154】[Ipsc2015]Generating Synergy KD-tree

    题目描述 给定一棵以1为根的有根树,初始所有节点颜色为1,每次将距离节点a不超过l的a的子节点染成c,或询问点a的颜色 输入 第一行一个数T,表示数据组数 接下来每组数据的第一行三个数n,c,q表示结 ...

  7. BZOJ 1731: [Usaco2005 dec]Layout 排队布局

    Description Like everyone else, cows like to stand close to their friends when queuing for feed. FJ ...

  8. 静态区间第k大 树套树解法

    然而过不去你谷的模板 思路: 值域线段树\([l,r]\)代表一棵值域在\([l,r]\)范围内的点构成的一颗平衡树 平衡树的\(BST\)权值为点在序列中的位置 查询区间第\(k\)大值时 左区间在 ...

  9. css实现0.5像素

    .border{ position: relative; } .border:before{ content: ''; position: absolute; width: 200%; height: ...

  10. codechef AUG17 T2 Chef and Mover

    Chef and Mover Problem Code: CHEFMOVR Chef's dog Snuffles has so many things to play with! This time ...