0

I wanted to implement automatically horizontal scroll for the situation if my Text is too long. It worked when the activity is empty without anything focus on. But when I tried implement this in an activity with chronometers, it's not working. I tested it out without chronometer it works. I tried to use setSelected(true), it's not working also. Is there any way to solve this, I need the scrolling function with the chronometer. Any comments and answer would be appreciated.

ScrollTextView.class

public class ScrollingTextView extends TextView{

public ScrollingTextView(Context context, AttributeSet attrs,
        int defStyle){
    super(context, attrs, defStyle);
}

public ScrollingTextView(Context context, AttributeSet attrs){
    super(context, attrs);
}

public ScrollingTextView(Context context){
    super(context);
}

@Override
protected void onFocusChanged(boolean focused, int direction,
        Rect previouslyFocusedRect){
    if(focused){
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
    }
}

@Override
public void onWindowFocusChanged(boolean focused){
    if(focused){
        super.onWindowFocusChanged(focused);
    }
}

@Override
public boolean isFocused(){
    return true;
}
}

TextView

<com.android.app.ScrollingTextView
    android:id="@+id/display_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:paddingLeft="10dp"
    android:paddingTop="10dp"
    android:singleLine="true"
    android:text="Display Message"
    android:textSize="18dp"
    android:textColor="#ffffff"
    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusableInTouchMode="true"/>
IssacZH.
  • 1,457
  • 3
  • 24
  • 54

2 Answers2

0

Add this in your XML

I've figured it out by myself.

android:focusable="true" 

& then try again.

Edit :

i face this problem

In my case this is the reason why Textview is not Scrolling is that,

i put a listview in above textview so the textview is not scrolling. so itried this one

set listview focusable is false

listview.setfocusable(false);

then it works the text was scrolling.

Dixit Patel
  • 3,190
  • 1
  • 24
  • 36
  • But in my activity I don't have listview, I tried `.setFocusable(false);` on chronometer. It's not working as well. – IssacZH. Jan 16 '13 at 09:49
0

Try this, it may help you.

<TextView
            android:id="@+id/textView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:onClick="onClick" 
            android:smoothScrollbar="true"
            android:scrollbars="vertical"
             android:maxLines="6"
            android:ellipsize="none"
            android:scrollHorizontally="false"
            android:singleLine="false"
            />
Amit Jayaswal
  • 1,725
  • 2
  • 19
  • 36