欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android仿支付寶中余額寶的數(shù)字動畫效果

 更新時間:2016年08月30日 15:07:20   作者:李晨瑋  
最近因為工作需要高仿余額寶數(shù)字動畫效果,達到炫酷的數(shù)字動畫效果,所以寫出了分享給大家,有需要的朋友可以直接拿來用,下面一起來看看。

實現(xiàn)效果圖:

下面是具體代碼,可直接復制:

package com.lcw.rabbit.widget;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.TextView;

/**
 * 高仿余額寶數(shù)字動畫
 * Create by: chenwei.li
 * Date: 2016-07-20
 * time: 11:52
 * Email: lichenwei.me@foxmail.com
 */
public class CountNumberView extends TextView {
 //動畫時長
 private int duration = 1500;
 //顯示數(shù)字
 private float number;
 //顯示表達式
 private String regex;

 //顯示表示式
 public static final String INTREGEX = "%1$01.0f";//不保留小數(shù),整數(shù)
 public static final String FLOATREGEX = "%1$01.2f";//保留2位小數(shù)

 public CountNumberView(Context context, AttributeSet attrs) {
 super(context, attrs);
 }

 /**
 * 顯示帶有動畫效果的數(shù)字
 * @param number
 * @param regex
 */
 public void showNumberWithAnimation(float number, String regex) {
 if (TextUtils.isEmpty(regex)) {
  //默認為整數(shù)
  this.regex = INTREGEX;
 } else {
  this.regex = regex;
 }
 //修改number屬性,會調用setNumber方法
 ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(this, "number", 0, number);
 objectAnimator.setDuration(duration);
 //加速器,從慢到快到再到慢
 objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
 objectAnimator.start();
 }

 /**
 * 獲取當前數(shù)字
 * @return
 */
 public float getNumber() {
 return number;
 }

 /**
 * 根據(jù)正則表達式,顯示對應數(shù)字樣式
 * @param number
 */
 public void setNumber(float number) {
 this.number = number;
 setText(String.format(regex, number));
 }
}

使用方法,在XML里聲明后(可以完全當成TextView來使用),直接在Java文件里調用:

 mTvCountNum1.showNumberWithAnimation(3201.23f, CountNumberView.FLOATREGEX);
 mTvCountNum2.showNumberWithAnimation(65535f, CountNumberView.INTREGEX);

這里為了靈活使用,預留了數(shù)字顯示格式(默認提供整型號和浮點型),大家可以根據(jù)自己的需要去更改Regex

關于String.format的第一個格式參數(shù),這里引用下api的描述:

常規(guī)類型、字符類型和數(shù)值類型的格式說明符的語法如下:

%[argument_index$][flags][width][.precision]conversion

可選的 argument_index 是一個十進制整數(shù),用于表明參數(shù)在參數(shù)列表中的位置。第一個參數(shù)由 "1$" 引用,第二個參數(shù)由 "2$" 引用,依此類推。

可選 flags 是修改輸出格式的字符集。有效標志集取決于轉換類型。

可選 width 是一個非負十進制整數(shù),表明要向輸出中寫入的最少字符數(shù)。

可選 precision 是一個非負十進制整數(shù),通常用來限制字符數(shù)。特定行為取決于轉換類型。

總結

Android仿支付寶中余額寶的數(shù)字動畫效果到這就結束了,希望這篇文章對大家在Android開發(fā)中能有所幫助,如果有疑問可以留言交流。

相關文章

最新評論