Android UI - TextTicker 棒棒哒的数字切换效果
2016-09-04 10:53
162 查看
效果
What is Ticker?
Ticker is a simple Android UI component for displaying scrolling text. Think about how an odometer scrolls when going from one number to the next, that is similar to what Ticker does. The Ticker handles smooth animations between strings and also string resizing (e.g. animate from “9999” to “10000”).You can specify how the animations proceed by defining an array of characters in order. Each character displayed by Ticker is controlled by this array which dictates how to animate from a starting character to a target character. For example, if you just use a basic ASCII character list, when animating from ‘A’ to ‘Z’, it will go from ‘A’ -> ‘B’ -> … ‘Z’. The character ordering does not wrap around, meaning that to animate from ‘Z’ to ‘A’ it will go from ‘Z’ -> ‘Y’ -> … -> ‘A’.
Getting started
Add the ticker dependency to your build.gradle.compile 'com.robinhood.ticker:ticker:1.1.0'
Usage
Define the TickerView in XML:<com.robinhood.ticker.TickerView android:id="@+id/tickerView" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Then add the character array to specify the animation style:
final TickerView tickerView = findViewById(R.id.tickerView); tickerView.setCharacterList(TickerUtils.getDefaultNumberList());
That’s it! Now you can call setText to display your data.
Customization
We currently support a fairly limited subset of customizations at the moment so please let us know what new features / APIs you need exposed for your use-case and we’ll consider it for future releases (or of course feel free to fork!).You can customize the looks and feels of the TickerView via XML:
android:gravity="center" android:textColor="@color/colorPrimary" android:textSize="16sp" app:ticker_animationDuration="1500"
Or Java:
tickerView.setTextColor(textColor); tickerView.setTextSize(textSize); tickerView.setTypeface(myCustomTypeface); tickerView.setAnimationDuration(500); tickerView.setAnimationInterpolator(new OvershootInterpolator()); tickerView.setGravity(Gravity.START);
Note that you can also specify android:textColor and android:textSize attributes using android:textAppearance and provide it with an appropriate style.
Performance
We decided to extend from the base View class and achieve everything by drawing directly onto the canvas. The primary benefit from this is having full flexibility and control over memory allocations and minimize performance impact by using native draw operations. We pre-allocate and pre-compute as much as possible for each transition so that the only thing we need to do in the draw path is perform the actual drawing operations. The performance test UI included in the ticker-sample is a bit over-zealous but animates smoothly with a screen full of tickers.Github
Ticker相关文章推荐
- TextSwitcher,一个带有文字切换动画效果的加强版TextView
- TextView 数字、中文 内容的中线下划线锯齿效果实现
- Android 仿日历翻页、仿htc时钟翻页、数字翻页切换效果
- Android实现连续并排的若干个TextView单击改变背景颜色达到选项卡Tab栏切换效果
- android edittext切换数字键盘
- EditText想要让默认输入类型为数字,并且可以切换到其他输入类型
- EditText可编辑状态和不可编辑状态切换 及其它特殊效果
- EditText首选输入数字,可以切换输入中文英文
- Android实现数字跳动效果的TextView方法示例
- 基于HTML5+css3的数字反转切换效果
- android 多行textview间切换跑马灯效果
- viewpager滑动fragment点击textview切换页面线条滑动效果
- Android实现连续并排的若干个TextView单击改变背景颜色达到选项卡Tab栏切换效果
- Android TextView实现跑马灯效果
- 图片切换效果
- 图像处理------简单数字水印 - 文字轧花效果
- Android 中ViewPager 实现动画效果切换
- JS图片滚动切换效果
- css3实现手机效果的“切换标签”
- 新的限制Text文本只能输入数字的方法