Android 如何确定编辑字段的大小

Android 如何确定编辑字段的大小,android,layout,android-edittext,Android,Layout,Android Edittext,我正在开发一个android应用程序,在这个应用程序中,我想修正editfield框的大小。例如,如果我想在上面添加100个单词,那么它不会增加编辑字段的大小。字符应保留在框内,而不增加编辑文本的大小。我已经将editText的xml代码与图像一起粘贴 <EditText android:id="@+id/fnametxt" android:

我正在开发一个android应用程序,在这个应用程序中,我想修正editfield框的大小。例如,如果我想在上面添加100个单词,那么它不会增加编辑字段的大小。字符应保留在框内,而不增加编辑文本的大小。我已经将editText的xml代码与图像一起粘贴

                   <EditText
                            android:id="@+id/fnametxt"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1.1"
                            android:background="@color/Beige"
                            android:enabled="false"
                            android:lines="1"
                            android:ems="15"
                            android:maxLines="1"
                            android:scrollHorizontally="true"
                            android:singleLine="true"
                            android:text="ufyufgiuhjlkh"
                            android:textColor="@color/Black"
                            android:textSize="12sp" />

提前感谢更改:

android:layout_width="wrap_content"
差不多

android:layout_width="200dp"

或者您选择的任何尺寸。

如果您打算使用“布局重量”属性设置高度,请设置

layout_height="0"
否则设置

layout_height="100dp" 

或者您希望固定高度是什么。

也许您需要使用XML-android:maxLines和android:lines属性并操纵maxLength

<EditText
          android:id="@+id/fnametxt"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_weight="1.1"
          android:background="@color/Beige"
          android:enabled="false"
          android:lines="5"
          android:ems="15"
          android:maxLines="100"
          android:scrollHorizontally="true"
          android:singleLine="true"
          android:text="ufyufgiuhjlkh"
          android:textColor="@color/Black"
          android:textSize="12sp" />


来源:。

固定字段的宽度

您可以通过以下几种方式完成此操作:

  • 用砝码进行线性布局。您的容器应该有android:weightSum=“100”(您可以放置数字,而不是100)。例如,你可以去,也可以去。使用权重,您应该设置android:layout\u width=“0dp”,以查看结果

  • 与页边距相对应。将first EditText设置为
    android:layout\u alignParentRight=“true”
    android:layout\u toRightOf=“IdOfTextView”
    。将右边距设置为(例如)10dp。EditField将被拉伸以填充所有可用空间

  • 您可以将
    android:maxWidth
    设置为dp或px中的某个值。或者你能做到这一点