2

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

5 Answers 5

5

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

tv.setMovementMethod(new ScrollingMovementMethod()); 

in your java code.

1

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 
1

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

1
  • 1
    appreciate your answer buddy ..but I had already accepted a answer for my question .. but keep it up to earn some points :-P Aug 7, 2013 at 7:41
1

Try changing this:

android:layout_width="fill_parent"

to this:

android:layout_width="80dp"
0
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.