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" />

      

enter image description here thanks in advance

+3


source to share


4 answers


Edit:

android:layout_width="wrap_content"

      

To Something like



android:layout_width="200dp"

      

or any other size you choose.

+1


source


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 set android:layout_width="0dp"

    to see the result.

  • RelativeLayout with fields. Set the first EditText to android:layout_alignParentRight="true"

    and android: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.

+1


source


If you intend to set the height using layout_weight property then set

layout_height="0"

      

otherwise set

layout_height="100dp" 

      

or whatever you want your fixed height to be.

0


source


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 .

0


source







All Articles