1

I have a TextView with following attributes :

<TextView
        android:id="@+id/appheader" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_centerVertical="true"
        android:textColor="#ffffff"
        android:layout_marginLeft="3dp"
        android:textSize="21sp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:focusable="true"
        android:focusableInTouchMode="true"/> 

Actually the TextView scrolls ONLY when I click the TextView. But I want to scroll it automatically when I launch the Activity. How can I do this ?

Dileep Perla
  • 1,865
  • 7
  • 33
  • 54
  • "scroll it automatically" are you referring to marquee here? – waqaslam Apr 23 '12 at 07:29
  • Could you define "scroll" more? Because if you want it to scroll through the text that is in the TextView, you're gonna have a problem, since you've put it on singleLine="true". – Loyalar Apr 23 '12 at 07:30
  • have u check ans given by me it works try that – Khan Apr 23 '12 at 08:14
  • Why the text won't scroll if we set singleLine="true". Its working for me. – Dileep Perla Apr 23 '12 at 09:42
  • add in ur activity in which u have used textview TextView tv=(TextView)findViewById(R.id.appheader); tv.setSelected(true); – Khan Apr 23 '12 at 07:43

3 Answers3

2
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="very long text to srollll dkfjadkfjkldjfkjdkghjhtudhfjhdjfkdfkadjsajekdfjak" 
    android:singleLine="true" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:ellipsize="marquee"
    android:focusable="true" 
    android:focusableInTouchMode="true"/>
vtuhtan
  • 1,056
  • 7
  • 18
1

By-default TextView marquee effect works when it get focus. To make an automatic marquee effect you need to extend TextView class. See this link for reference.

Community
  • 1
  • 1
orchidrudra
  • 1,172
  • 1
  • 12
  • 30
1

set android:scrollHorizontally="true" for that textview.

Also set the following two properties:

text.setMovementMethod(new ScrollingMovementMethod());

text.setSelected(true);
benka
  • 4,732
  • 35
  • 47
  • 58
Puneet Akhouri
  • 41
  • 1
  • 2
  • 8