• android xml 布局文件中 android:ems="10"


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

  • 相关阅读:
    ThinkPHP Ajax 使用详解及实例
    thinkphp中常用的系统常量和系统变量
    JavaScript使用thinkPHP模板标签
    正则表达式替换连续空格
    javascript关联数组
    javascript关联数组的用法
    javascript之数组操作
    CentOS7_开放指定端口
    centos7磁盘基本信息
    SpringBoot thymeleaf——修改后如何实时生效
  • 原文地址:https://www.cnblogs.com/H-BolinBlog/p/5389516.html
Copyright © 2020-2023  润新知