Android ems是什么?为什么editfield大小(宽度)相同?

Android ems是什么?为什么editfield大小(宽度)相同?,android,android-layout,Android,Android Layout,我刚刚开始android开发,所以我有两个问题 首先,为什么编辑字段的大小不改变其宽度 第二,这两条线是什么意思 android:layout\u weight=“1.0” android:ems=“50” 当我在布局表单中使用android:layout\u weight=时,它的值为0.1,为什么 在现场,它需要1.0,为什么? 什么是ems <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi

我刚刚开始android开发,所以我有两个问题

  • 首先,为什么编辑字段的大小不改变其
    宽度

  • 第二,这两条线是什么意思

android:layout\u weight=“1.0”

android:ems=“50”

当我在布局表单中使用android:layout\u weight=时,它的值为
0.1
,为什么

在现场,它需要
1.0
,为什么? 什么是
ems

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/login_header" 
         android:gravity="center_horizontal"
         android:textSize="30dp" />

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
         android:padding="10dp" >

         <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/username"
            android:textSize="18dp"/>

           <EditText
            android:id="@+id/username"
            android:layout_width="5dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:ems="50"
            android:inputType="text"/ >

    </LinearLayout>

      <Button
        android:id="@+id/login"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/login_header"
        android:layout_margin="10dp"/>

</LinearLayout>

您的编辑文本宽度没有改变,因为您给编辑文本赋予了布局_权重=1,这意味着编辑文本将采用绘制时的水平线布局的剩余宽度

如果要在文本视图和EditText中使用.5布局权重。它们都将占据整个宽度的一半。它是一个水平线性布局,因此权重会影响视图的宽度。所以Edittext的宽度是无用的。如果是垂直线性布局,视图的高度将受到布局重量的影响

    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:padding="10dp" >

      <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/username"
        android:textSize="18dp"
        android:layout_weight=".5" />

       <EditText
        android:id="@+id/username"
        android:layout_width="5dp"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
        android:ems="50"
        android:inputType="text" >

     </EditText>
</LinearLayout>

Ems:-是一个印刷术语。有关ems检查的更多信息