zoukankan      html  css  js  c++  java
  • 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和字符之间的关系,还没有了解。正常也很少用这玩意。

  • 相关阅读:
    移动端,多屏幕尺寸高清屏retina屏适配的解决方案
    angular 关于 factory、service、provider的相关用法
    2016最新手机号码正则、身份证JS正则表达式
    凸包总结
    BZOJ 3653: 谈笑风生(DFS序+可持久化线段树)
    BZOJ 3652: 大新闻(数位DP+概率论)
    BZOJ 1062: [NOI2008]糖果雨(二维树状数组)
    纪中集训 Day 8 & Last Day
    纪中集训 Day 7
    纪中集训 Day 6
  • 原文地址:https://www.cnblogs.com/H-BolinBlog/p/5389516.html
Copyright © 2011-2022 走看看