代码之家  ›  专栏  ›  技术社区  ›  Rk R Bairi

对齐并调整文本视图和编辑行中文本的宽度

  •  1
  • Rk R Bairi  · 技术社区  · 7 年前

    在当前布局中,EditText对齐,但显示为收缩,不占用剩余宽度

    enter image description here

    Xml

     <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:style="@style/AppTheme"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp">
    
            <TableRow>
                <TextView
                    style="@style/AppTheme.DetailInfo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="New Password:" />
                <EditText
                    style="@style/AppTheme.TextBox"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:text= "@={profile.password}"/>
            </TableRow>
       </TableLayout>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   andrewoid    7 年前

    如果希望编辑文本填充剩余空间,则应设置其布局宽度=“0dp”和布局重量=“1”。请参阅:

    https://developer.android.com/guide/topics/ui/layout/linear.html#Weight

    编辑:如果你想让编辑文本的开头对齐,你应该对所有的文本视图应用相同的权重,对所有的编辑文本应用相同的权值。原始答案只会填满剩余的空间,而不会保持文本的开头对齐。