Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a long string in a text view in a single line with horizontal scroll

Tags:

android

actually i have keep one scrollview. Inside that scroll view I set one textview at run time I want to set text in that textview. The string which I'm going to set is some what big in length so i could not get the string in a single line and i can get my string two or three lines. My scroll view layout width size is 250px. I dont want to exceed that size...My expectation is i want to see that string within that scrollview as single line if the string is exceeds the scroll size then it should horizontally scroll in text view. I tried some functions like setting horizontal scroll to scrollview and textview but nothing is work out. Pls help me how to solve this problem.

urs,

s.kumaran.

like image 210
Kumar Avatar asked Jul 17 '09 06:07

Kumar


3 Answers

you have to use these two Xml attributes in your TextView widget:

android:scrollHorizontally="true"

android:singleLine="true"

So your xml layout must contain something like this:

<TextView
        android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget" 
        android:singleLine="true" 
        android:ellipsize="marquee"
        android:marqueeRepeatLimit ="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true" 
        android:scrollHorizontally="true"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>

you can get the correspondant method for these attributes if you are creating Your TextView with code, refer to TextView documentation :

setHorizontallyScrolling(boolean)
setTransformationMethod(TransformationMethod)
setMarqueeRepeatLimit(int)
like image 85
K_Anas Avatar answered Nov 03 '22 04:11

K_Anas


try this ,,

TextView.setHorizontallyScrolling(true) TextView.setLines(1);

where did you add the textview..Inside scrollview we able to add only one view...

like image 43
arams Avatar answered Nov 03 '22 03:11

arams


Take TextView and HorizontalScrollView. Just put textview inside the HorizontalScrollView. And yes make sure to mentioned android:singleLine="true" inside the TextView.

like image 40
Paresh Mayani Avatar answered Nov 03 '22 05:11

Paresh Mayani