Android TextView的子类实现了数字自动增长或减小:TextCounter

y37f 9年前

TextCounter是Android TextView的子类,实现了文本中的数字自动增长或减小。

Download

Gradle

compile 'com.github.premnirmal:TextCounter:1.1.0'

Maven Central

<dependency>    <groupId>com.github.premnirmal</groupId>    <artifactId>TextCounter</artifactId>    <version>1.1.0</version>    <type>aar</type>  </dependency>

Usage

Xml
  <com.github.premnirmal.textcounter.CounterView          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_marginBottom="20dp"          android:textSize="30dp"          android:textColor="@color/orange"          counter:autoStart="true"          counter:startValue="100"          counter:endValue="5000"          counter:incrementValue="100"          counter:timeInterval="2"          counter:prefix="$"          counter:suffix=" moneys"          counter:type="integer | decimal | both"          />

Java
final CounterView counterView = new CounterView(context);  counterView.setFormatter(new Formatter() {      @Override      public String format(String prefix, String suffix, float value) {      return prefix           + NumberFormat.getNumberInstance(Locale.US).format(value)           + suffix;      }  });  counterView.setAutoStart(false);  counterView.setStartValue(200f);  counterView.setEndValue(1000f);  counterView.setIncrement(5f); // the amount the number increments at each time interval  counterView.setTimeInterval(2); // the time interval (ms) at which the text changes  counterView.setPrefix("You have ");  counterView.setSuffix(" points!");  counterView.start(); // you can start anytime if autostart is set to false

Formatter

You can control the text formatting by providing a Formatter. Simply implement the interfacecom.github.premnirmal.textcounter.Formatteror use one of the formatters under thecom.github.premnirmal.textcounter.formatterspackage.

项目主页:http://www.open-open.com/lib/view/home/1426473122554