RollingTextView


features

  • Simple to use, the API is similar to that of TextView, and the setText method can be animated with scrolling up and down
  • Support for XML set android: textSize/android: textColor/android: textStyle common properties, etc
  • Highly customizable, supports scrolling up and down for any single character

Animation effects

strategy

You can set different animation strategies to achieve different scrolling effects

The default animation is to scroll down as a small character changes to a large character and up as a small character changes to a large character

You can also specify to scroll in the same direction

Carry animation can carry from the lowest digit to the highest digit, not just for decimal. But can only be used for strings of less than 10 characters to prevent overflow of integers. Can only be used for character sequences containing zeros, otherwise the carry calculation is meaningless.

Character order

  • The character order needs to be set by itself. Tell the RollingTextView how to scroll from the original character to the target character
  • Common character sequences can be found inCharOrderFound in constants
  • When multiple orders are added that apply to both the target character and the original character, the precedence set above is higher
alphaBetView.addCharOrder(CharOrder.Alphabet);
alphaBetView.addCharOrder(CharOrder.UpperAlphabet);
alphaBetView.addCharOrder(CharOrder.Number);
alphaBetView.addCharOrder(CharOrder.Hex);
alphaBetView.addCharOrder(CharOrder.Binary);
Copy the code

Rolling smoothness

You can adjust the smoothness of the animation by passing a factor parameter. The closer the factor value is to 0.0, the scrolling will look jumpy. The closer the factor value is to 1.0, the smoother the scrolling

other

More ideas can implement the CharOrderStrategy interface and customize your own animations

configuration

  1. Add the following to the project build.gradle file in the App root directory:

    allprojects {
     	repositories {
     		...
    		maven { url 'https://jitpack.io'}}}Copy the code
  2. Add dependencies to the corresponding Module:

    dependencies {  
        compile 'com. Making. YvesCheung: RollingText: 1.2.0'
    }
    Copy the code

use

XML setup

<com.yy.mobile.rollingtextview.RollingTextView
    android:id="@+id/alphaBetView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="i am text"
    android:textSize="25sp" 
    android:textColor="#1d1d1d"
    android:textStyle="bold"
    android:gravity="center"
    android:shadowColor="#ffdd00"
    android:shadowDx="4dp"
    android:shadowDy="4dp"/>
Copy the code

Code sets

final RollingTextView rollingTextView = findViewById(R.id.alphaBetView);
rollingTextView.setAnimationDuration(2000L);
rollingTextView.setCharStrategy(Strategy.NormalAnimation);
rollingTextView.addCharOrder(CharOrder.Alphabet);
rollingTextView.setAnimationInterpolator(new AccelerateDecelerateInterpolator());
rollingTextView.addAnimatorListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        //finsih}}); rollingTextView.setText("i am a text");
Copy the code

Project address: github.com/YvesCheung/…