宽度为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和字符之间的关系,还没有了解。正常也很少用这玩意。

最新文章

  1. PHP封装
  2. 1&#183;3 对 git 的认识
  3. Discuz论坛安全加固浅析
  4. JS正则获取参数值
  5. C# 鼠标穿透窗体功能
  6. UI进阶 数据加密
  7. VS2015编译器问题简单记录
  8. 禁用UITableViewCell 重用机制
  9. 高精度运算专题1-加法运算(The addition operation)
  10. windows平台安装maven
  11. NodeJS脚本启动工具总结
  12. js原型链结构与链表结构对比
  13. angular ztree 梯形结构json配置、点击节点事件、默认展开所有
  14. UML教程
  15. 数据库 之 E-R设计感想
  16. C++STL priority_queue
  17. String js删除字符串的最后一个字符三种方法
  18. 微服务之springCloud-docker-feign-hystrix(六)
  19. angularJS $http $q $promise
  20. jacoco统计自动化测试代码覆盖率

热门文章

  1. Ubuntu下禁用笔记本自带键盘
  2. BZOJ2716 [Violet 3]天使玩偶 【CDQ分治】
  3. JAVA本地文本读取---解决中文乱码
  4. 排序(sortb)
  5. nginx支持pathinfo
  6. bzoj 1111 - 四进制的天平
  7. 汕头市队赛 SRM 08 C
  8. JS将JSON日期转换为指定格式的日期
  9. 编程中的runtime_error问题
  10. Juce之旅-第一个例子(图形窗口)