Skip to content

Instantly share code, notes, and snippets.

@LeonardoCardoso
Last active January 21, 2022 07:37
Show Gist options
  • 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 -->
@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