android - 如何使编辑字段android的固定大小

标签 android layout android-edittext

我正在开发 android 应用程序,我想在其中修复编辑字段框的大小。例如,如果我想在上面添加 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" />

enter image description here 提前致谢

最佳答案

固定字段的宽度。

您可以通过多种方式做到这一点:

  1. 带权重的线性布局。你的容器应该有 android:weightSum="100"(你可以放置你的号码而不是 100)。例如你可以去herehere .使用权重,您应该设置 android:layout_width="0dp" 以查看结果。

  2. 带边距的 RelativeLayout。将第一个 EditText 设置为 android:layout_alignParentRight="true"android:layout_toRightOf="IdOfTextView"。将右边距设置为(例如)10dp。 EditField 将被拉伸(stretch)以填充所有可用空间。

  3. 您可以将 android:maxWidth 设置为某个以 dp 或 px 为单位的值。或者 maxLengthmaxEms可以做到这一点。

关于android - 如何使编辑字段android的固定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27606154/

相关文章:

android - Firebase 身份验证超时

android - 将常量文本放在 EditText 中,它应该是不可编辑的 - Android

java - 字符串操作每 4 个字符插入一个字符

java - Android:语言更改后刷新当前 fragment

java - 在开始 Activity 之前需要单击“下一步”按钮两次

android - 启动 Activity 时错误膨胀类 android.support.v7.widget.RecyclerView

android - 我的 Android 应用程序能否在任何给定时刻知道并检测手机在哪个运营商下运行?

android - 如何更改 SwipeRefreshLayout 中的样式 progerssbar?

java - GroupLayout 边距/填充是自动生成的吗?

java - 如何从以编程方式膨胀的布局中访问 View ?