Anil
Anil

Reputation: 83

how to apply marquee in android for string

I am trying to implement marquee a style to print string in android. I'm able to to it with static data but for dynamic it isn't displaying the marquee style.

When I print:

String st="this is test application testing for marquee"

I get the marquee style.

However, after parsing when I'm getting data:

<TextView
        android:id="@+id/twxmorq"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:padding="5dip"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textColor="#FF0000" />

I run:

myString = myString + "| "+ json_data.getString("news_title").toString();

txt1 = (TextView) findViewById(R.id.twxmorq);
txt1.setText(myString1);

and I don't get the marquee style when I print mystring.

Please help me.

Summary: For the string ' ST ' I'm getting a marquee style printed string but for mystring1 I am not getting marequee style.

Upvotes: 3

Views: 1500

Answers (1)

Dipak Keshariya
Dipak Keshariya

Reputation: 22291

Use below code for that.

<TextView
    android:id="@+id/twxmorq"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:padding="5dip"
    android:scrollHorizontally="true"
    android:singleLine="true"
    ndroid:lines="1"
    android:textColor="#FF0000" 
    android:fadingEdge="horizontal"/>

Java Code:-

myString = myString + "| "+ json_data.getString("news_title").toString();

txt1 = (TextView) findViewById(R.id.twxmorq);
txt1.setSelected(true);
txt1.setText(myString1);

Upvotes: 1

Related Questions