带滚动动画的 Android TextView RollingTextView

码农软件 · 软件分类 · Android UI 组件 · 2019-04-23 13:41:57

软件介绍

RollingTextView

特性

  • 使用简单,API与TextView类似,setText方法可带有上下滚动的动画

  • 支持xml设置android:textSize/android:textColor/android:textStyle等常用属性

  • 可高度定制,支持任何单个字符的上下滚动变化效果

动画效果

策略

可以通过设置不同的动画策略来实现不同的滚动效果

默认的动画是小字符向大字符变化时向下滚动,反之向上滚动

也可以指定让滚动向同一个方向

进位动画可以从低位数字进位到高位数字,不止是适用于十进制。但只能用于长度小于10的字符串防止溢出整型数。只能用于包含0的字符序列,否则进位的计算将没有意义。

字符的顺序

  • 字符的顺序需要自行设置,告诉RollingTextView怎么从原字符滚动变化到目标字符

  • 常用的字符顺序可以在 CharOrder 常量中找到

  • 当添加多个顺序时且都适用于目标字符和原字符,前面设置的优先级会更高

alphaBetView.addCharOrder(CharOrder.Alphabet);
alphaBetView.addCharOrder(CharOrder.UpperAlphabet);
alphaBetView.addCharOrder(CharOrder.Number);
alphaBetView.addCharOrder(CharOrder.Hex);
alphaBetView.addCharOrder(CharOrder.Binary);

charOrderCompare

滚动流畅度

可以通过传递一个 factor 参数来调整动画的流畅度。 factor 值越接近0.0,滚动会显得比较跳跃。而 factor 值越接近1.0,滚动越平滑

stickyFactor

其他

更多的想法可自行实现 CharOrderStrategy 接口,定制自己的动画效果

配置

  1. 在App根目录的project build.gradle文件中添加:

     allprojects {
          repositories {
              ...
             maven { url 'https://jitpack.io' }
          }
     }
  2. 在对应的module 中添加依赖:

     dependencies {  
         compile 'com.github.YvesCheung:RollingText:1.2.0'
     }

使用

xml设置

<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"/>

代码设置

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");

许可证

Copyright 2018 Yves Cheung

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

本文地址:https://www.codercto.com/soft/d/4211.html

深入理解C指针

深入理解C指针

[美] Richard Reese / 陈晓亮 / 人民邮电出版社 / 2014-2 / 45.00

深入理解C指针和内存管理,提升编程效率!这是一本实战型图书,通过它,读者可以掌握指针动态操控内存的机制、对数据结构的增强支持,以及访问硬件等技术。本书详细阐述了如何在数组、字符串、结构体和函数中使用指针,同时演示了相应的内存模型及其对指针使用的影响。 指针为C语言带来了强大的功能和灵活性,却也是C语言中最难啃的一块“骨头”。本书旨在帮读者透彻理解指针,解决这个老大难问题。不论是初学者还是经验......一起来看看 《深入理解C指针》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

html转js在线工具
html转js在线工具

html转js在线工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具