Abhijeet Farakate
Abhijeet Farakate

Reputation: 647

How to get EditText of one line which scroll horizontally if text is long

I have set maxLines to 1 and scrollHorizontally to True but it's not working. It is giving multiline EditText which scrolls vertically.

       <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Work"
            android:maxLines="1"
            android:lines="1"
            android:scrollHorizontally="true"
            android:textSize="18sp"
            android:padding="4dp"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="48dp"/>

Upvotes: 0

Views: 304

Answers (6)

Monali
Monali

Reputation: 171

Try it

android:singleLine="true" 

Upvotes: 0

Abhijeet Gite
Abhijeet Gite

Reputation: 89

try adding this property:

singleLine="true"

Upvotes: 2

Sai Tarun Kaniganti
Sai Tarun Kaniganti

Reputation: 115

Use <EditText> inside <HorizontalScrollView>

Upvotes: 0

GianhTran
GianhTran

Reputation: 3711

I see you have a solution, but I show you another way, with this way, your text view can auto slide if it is too long, very interesting.

                 <TextView
                    android:id="@+id/text_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ellipsize="marquee"
                    android:marqueeRepeatLimit="marquee_forever"
                    android:scrollHorizontally="true"
                    android:singleLine="true"
                    android:text="marquee_forever marquee_forever marquee_forever marquee_forever"
                    android:textColor="@color/white"
                    android:textSize="12dp"
                    android:textStyle="bold"
                    />

Upvotes: 0

Rasel
Rasel

Reputation: 5734

Wrap EditTextin HorizontalScrollView

<HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="wrap_content"
            android:maxLines="1"
            android:layout_height="wrap_content" />
</HorizontalScrollView>

Upvotes: 1

Skizo-ozᴉʞS ツ
Skizo-ozᴉʞS ツ

Reputation: 20626

You have to add singleLine="true"

<EditText
        android:id="@+id/editTextHorizontalScroll"
        android:textSize="18sp"
        android:padding="4dp"
        android:layout_marginStart="32dp"
        android:layout_marginEnd="48dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Work" />

Upvotes: 0

Related Questions