Anand Phadke
Anand Phadke

Reputation: 531

Text in Text View not scrolling even i set ellipsize="marquee" in xml in android

my xml code is

 <TextView 
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_gravity="center_vertical"
 android:lines="1" 
 android:singleLine="true" 
 android:textColor="#ffffff"
 android:focusable="true"
 android:marqueeRepeatLimit="marquee_forever" 
 android:ellipsize="marquee" 
 android:typeface="serif"
 android:scrollHorizontally="true" 
 android:focusableInTouchMode="true"</TextView>

and i set text in Activity in onCreate method as below

textView.setText("some text ");             
textView.setSelected(true);             
textView.setFocusable(true);
textView.setFocusableInTouchMode(true);

it is working but when close application pressing back button and again restart it text not scroll and also when i change activity and come to the activity where this text view present i wont scroll ?also i tried custom text view

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.TextView;

public class CustomTextView extends TextView {
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@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;
}

}

but it wont work

Upvotes: 2

Views: 2934

Answers (5)

Shishir Shetty
Shishir Shetty

Reputation: 2049

Try changing this:

android:layout_width="fill_parent"

to this:

android:layout_width="80dp"

Upvotes: 1

JWqvist
JWqvist

Reputation: 717

Sometimes you need to requestfocus on the TextView before it will scroll.

Upvotes: 1

Pradeep Sodhi
Pradeep Sodhi

Reputation: 2145

You have to use android:scrollbars = "horizontal" in xml file, then use

tv.setMovementMethod(new ScrollingMovementMethod()); 

in your java code.

Upvotes: 5

Bhavesh Vadalia
Bhavesh Vadalia

Reputation: 369

Your code is correct but you have to put text length greater than your device width.

Upvotes: 0

Vinit ...
Vinit ...

Reputation: 1459

Change your layout as ScrollView

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
</ScrollView 

Upvotes: 1

Related Questions