安卓开发之数据变动动画效果开源库ticker使用!
1.到底是什么?
ticker是一个简单的AndroidUI组件,用于显示滚动文本。想想一个里程计在从一个数字滚动到下一个数字时是如何滚动的,这类似于Ticker所做的事情。Ticker处理字符串之间的平滑动画和字符串大小调整(例如,动画从“9999”到“10000”)。
2.开始
将ticker依赖项添加到build.gradle.
implementation 'com.robinhood.ticker:ticker:2.0.1'
使用
定义TickerView在XML中:
<com.robinhood.ticker.TickerView
android:id="@+id/tickerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
然后添加字符数组以指定动画样式:
final TickerView tickerView = findViewById(R.id.tickerView);
tickerView.setCharacterLists(TickerUtils.provideNumberList());
就这样!现在你可以设置setText显示你的数据。
定制化:
您可以自定义TickerView通过XML:
android:gravity="center"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
app:ticker_animationDuration="1500"
app:ticker_preferredScrollingDirection="any"
或者Java:
tickerView.setTextColor(textColor);
tickerView.setTextSize(textSize);
tickerView.setTypeface(myCustomTypeface);
tickerView.setAnimationDuration(500);
tickerView.setAnimationInterpolator(new OvershootInterpolator());
tickerView.setGravity(Gravity.START);
tickerView.setPreferredScrollingDirection(TickerView.ScrollingDirection.ANY);
完毕!!