Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving text in textView android

Tags:

android

I would like to ask you if textview has any option that when I have too long text for example text has 30 dp and textview has 15 dp I want to show text which is moving from left corner to right and return to start and again. Something like animation. I want to user see all text. Something like automatic scroll.

Edit: How I can do that in code, not xml?

like image 925
user1302569 Avatar asked Oct 25 '12 08:10

user1302569


People also ask

What is marquee text in Android?

TextView is used here to add the text which we want to display on the screen. Here we have used android:ellipsize=”marquee” to add a marquee to our text and android:singleLine=”true” so that our text will show only in one line.

What must be done to a TextView to make it scrollable with a visible scrollbar?

To make TextView scrollable, you don't need to use ScrollView, just add android:scrollbars=”vertical” attribute in TextView and then add two line of code in your java activity file. Following is the xml layout file which contain a LinearLayout and a TextView.


2 Answers

an example -

in the XML :

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:textColor="#ff4500"
        android:text="this is a very long piece of text that will move" />
</RelativeLayout>

in Java:

        tv = (TextView) this.findViewById(R.id.tv);  
        tv.setSelected(true);  // Set focus to the textview
like image 75
Vinay W Avatar answered Oct 03 '22 05:10

Vinay W


You should use android:ellipsize="marquee".

EDIT: you can use textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);

like image 44
Ovidiu Latcu Avatar answered Oct 03 '22 05:10

Ovidiu Latcu