if (!isRunning()) {
mPlayingState = RUNNING;
if (numberType==1)
runInt();
else
runFloat();
}
}
@Override
public RiseNumberTextView withNumber(float number) {
this.number=number;
numberType=2;
if (number>1000){
fromNumber=number-(float)Math.pow(10,sizeOfInt((int)number)-2);
}else {
fromNumber=number/2;
}
return this;
}
@Override
public RiseNumberTextView withNumber(int number) {
this.number=number;
numberType=1;
if (number>1000){
fromNumber=number-(float)Math.pow(10,sizeOfInt((int)number)-2);
}else {
fromNumber=number/2;
}
return this;
}
@Override
public RiseNumberTextView setDuration(long duration) {
this.duration=duration;
return this;
}
@Override
public void setOnEnd(EndListener callback) {
mEndListener=callback;
}
}
将这两个类集成到我们的工程中后,就可以使用了,下面这个是使用范例:
package com.bear.risenumbertest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
import com.bear.risenumbertest.lib.RiseNumberTextView;
import com.bear.risenumbertest.lib.RiseNumberTextView.EndListener;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取到RiseNumberTextView对象
RiseNumberTextView rnTextView = (RiseNumberTextView) findViewById(R.id.risenumber_textview);
// 设置数据
rnTextView.withNumber(2666.50f);
// 设置动画播放时间
rnTextView.setDuration(5000);
// 开始播放动画
rnTextView.start();
// 监听动画播放结束
rnTextView.setOnEnd(new EndListener() {
@Override
public void onEndFinish() {
Toast.makeText(MainActivity.this, "数据增长完毕...",
Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
附上效果图:
最后附上Android之增长的数字动画完整的工程源码链接:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2014年资料/12月/15日/Android之增长的数字
------------------------------------------分割线------------------------------------------