https://github.com/kornan/DigitalChangeView/
简介:
这是一个用于实现像支付宝数字动画控件;
Gradle:
compile 'net.kornan.digitalchange:digitalchange:0.0.1'
使用方法:
<net.kornan.view.DigitalChangeView
android:id="@+id/text_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultValue="100" />
//支持小数和整数
textNumber.setNumber(100);
textNumber.setNumber(100, 3);
textNumber.setDuration(500);
//开始动画
textNumber.start();
PS:app:defaultValue是用来设置默认值。
public class DigitalActivity extends AppCompatActivity implements DigitalChangeView.EndListener {
private DigitalChangeView textNumber;
private EditText editInput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_digtal);
editInput = (EditText) findViewById(R.id.edit_input);
textNumber = (DigitalChangeView) findViewById(R.id.text_number);
textNumber.setOnEndListener(this);
}
public void onClickView(View v) {
try {
switch (v.getId()) {
case R.id.btn_submit:
String strValue = editInput.getText().toString();
if (isInteger(strValue)) {
textNumber.setNumber(Integer.parseInt(strValue));
} else if (isDecimal(strValue)) {
textNumber.setNumber(Float.parseFloat(strValue), 2);
} else {
return;
}
textNumber.setDuration(500);
textNumber.start();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean isDecimal(String str) {
if (str == null || "".equals(str))
return false;
java.util.regex.Pattern pattern = Pattern.compile("[0-9]*(\\.?)[0-9]*");
return pattern.matcher(str).matches();
}
public static boolean isInteger(String str) {
if (str == null)
return false;
Pattern pattern = Pattern.compile("[0-9]+");
return pattern.matcher(str).matches();
}
@Override
public void onEndFinish() {
Log.d("digital", "onEndFinish");
}
}
网友评论