Skip to content

Instantly share code, notes, and snippets.

@LeonardoCardoso
Last active January 21, 2022 07:37
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeonardoCardoso/1116723900c815a48496 to your computer and use it in GitHub Desktop.
Save LeonardoCardoso/1116723900c815a48496 to your computer and use it in GitHub Desktop.
TextView with continuous scroll marquee animation no matter where the Activity focus is.
public class ScrollTextView extends TextView {
public ScrollTextView(Context context) {
super(context);
}
public ScrollTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@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;
}
}
<com.your.package.ScrollTextView
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
/>
<!-- add your other attrs on your textview -->
@nesttle
Copy link

nesttle commented May 2, 2020

Hello friend, do you know why this solution does not work for me?
My dynamically added TextViews with FCM messages are generated paused and without movement,
unlike the TextViews that I generate from the beginning :(

@rohit19img
Copy link

but it takes a pause for second before it scrolls again, how can we remove this?

@AnkitKumarMaurya
Copy link

Thanks It is working for me but end of the TextView it is showing some space how I can remove this. Scrolling is working fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment