宽度为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. corosync.conf

    ##totem定义集群内各节点间是如何通信的,totem本是一种协议,专用于corosync专用于各节点间的协议,协议是有版本的 totem { ##版本号 version: ##安全认证on|off ...

  2. SPOJ 364 Pocket Money 简单DP

    跟矩阵链乘同类型的题…… 输出用%llu不是%I64u…… 几组数据: 141+2*4+3*4+5*00*5*6+7*3+23+0+6+7+0+44*5+7*1*1+12*0+3*4*0+5*6+7+ ...

  3. css控制文字模糊

    *{ color: transparent; text-shadow: #111 0 0 5px; }

  4. nginx的入门到框架设计

    mac上安装nginx 安装与启动 安装 brew install nginx 命令 通过 Homebrew 下载的软件默认位置在 /usr/local/Cellar 应该ln-s 加连接就能全局 n ...

  5. JVM垃圾回收机制GC

    1. 垃圾回收的意义 在C++中,对象所占的内存在程序结束运行之前一直被占用,在明确释放之前不能分配给其它对象:而在Java中,当没有对象引用指向原先分配给某个对象的内存时,该内存便成为垃圾.JVM的 ...

  6. 多线程和CPU的关系

    什么是CPU (1)         Central  Progressing  Unit 中央处理器,是一块超大规模的集成电路,是一台计算机的运算核心和控制核心. (2)         CPU包括 ...

  7. 文明距离(civil)

    文明距离(civil) 题目描述 你被一个一向箔打中了,现在你掉到了一个一维空间中,也就是一个数轴上. 在这个数轴上,每秒会在一段连续的区间上出现“文明”.而你在每一秒开始的时候,可以花费x的代价移动 ...

  8. Linux & Android 多点触摸协议

    Linux & Android 多点触摸协议 Android4.0多点触摸入门 1 KERNEL 对于触摸屏的驱动我们简单的划分为两个主要的部分,一个是注册,另一个是上报. 1.1 注册 单点 ...

  9. Windows下MySQL安装配置与使用

    1.下载. 下载地址: http://downloads.mysql.com/archives/get/file/mysql-5.7.11-winx64.zip. NavicatforMySQL:ht ...

  10. 第20章 HOOK和数据库访问

    转自: https://blog.csdn.net/u014162133/article/details/46573873 通过安装Hook过程,可以用来屏蔽消息队列中某些消息 The SetWind ...