How to fix android edit area size
I am working on an android application where I want to fix the size of the editfield. For example, if I want to add 100 words to it, it will not increase the size of the edit box. Symbols should remain inside the box without increasing the size of the edit text. I am pasting the xml of my editText along with the images.
<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" />
thanks in advance
source to share
Correct the field width.
You can do this in several ways:
-
LinearLayout with weights. Your container must have
android:weightSum="100"
(instead of 100 you can place your number). For example, you can go here or here . Using the scale, you must setandroid:layout_width="0dp"
to see the result. -
RelativeLayout with fields. Set the first EditText to
android:layout_alignParentRight="true"
andandroid:layout_toRightOf="IdOfTextView"
. Set the right margin (e.g. 10dp). The EditField will stretch to fill all the free space. -
You can set
android:maxWidth
to some value in dp or px. Or maxLength or maxEms might do the trick.
source to share
Maybe you need to use the android: maxLines and android: lines XML attribute and manipulate the 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" />
Source: Android OS Developers Max Lines .
source to share