Usman Khan
Usman Khan

Reputation: 3953

I inserted long text in Edit Text view increase its size in Android

I am working on an Android application in which I am using edit text. When I put long text in it, it increase the size of the edit text. I having already given "wrap_content" on width and limit the number of lines and 'ems' but it won't work.

When I put long text or short text it increases or decreases the size of edit text. I have post the XML code and snapshot of my problem.

<LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_weight="1"
                    android:orientation="vertical" >

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" >

                        <TextView
                            android:id="@+id/fname"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text=" First Name:"
                            android:textColor="@color/Black"
                            android:textSize="12sp" />

                        <EditText
                            android:id="@+id/fnametxt"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            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" />
                    </LinearLayout>

enter image description here

Upvotes: 0

Views: 978

Answers (3)

M S Gadag
M S Gadag

Reputation: 2057

try this.. by giving width it makes design compatibility complex

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_gravity="bottom"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="4" >

        <TextView
            android:id="@+id/fname"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=" First Name:"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:layout_weight="1" />

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

</LinearLayout> 

Upvotes: 0

Narendra Kumar
Narendra Kumar

Reputation: 581

Use Below Code it Works fine:

<LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >

                    <TextView
                        android:id="@+id/fname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text=" First Name:"
                        android:textColor="@color/Black"
                        android:textSize="12sp"
                        android:singleLine="true"/>

                    <EditText
                        android:id="@+id/fnametxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        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" />
                </LinearLayout>

Upvotes: 0

duggu
duggu

Reputation: 38439

Just fix the width size of textview :

<LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" >

                        <TextView
                            android:id="@+id/fname"
                            android:layout_width="100dp"
                            android:layout_height="wrap_content"
                            android:text=" First Name:"
                            android:textColor="@color/Black"
                            android:textSize="12sp" />

                        <EditText
                            android:id="@+id/fnametxt"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            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" />
                    </LinearLayout>

Upvotes: 3

Related Questions