Last active
January 21, 2022 07:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 --> |
but it takes a pause for second before it scrolls again, how can we remove this?
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
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 :(