Android TextView的子類實現了數字自動增長或減小:TextCounter
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</pre>
</h3>
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.
+ 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</pre>
</h3>
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.
本文由用戶 y37f 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!