在动画数字中添加格式化为货币的数字 (10,000)
Adding numbers formatted as currency in animated numbers (10,000)
我想为我的 activity.so 创建一个加载动画我使用了以下代码:
private void startCountAnimation() {
animator = ValueAnimator.ofInt(1000, 9000);
animator.setDuration(500);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.addUpdateListener((animation) -> {
tvCost.setText(animation.getAnimatedValue().toString());
});
animator.start();
}
这将计算 1000 到 9000。但我想在计算时使用货币格式。所以我希望结果显示为 1,000 到 9,000。
像这样格式化数字:
tvCost.setText(String.format("%10.0f", animation.getAnimatedValue()));
或本地货币:
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String currency = formatter.format(animation.getAnimatedValue());
tvCost.setText(currency);
我想为我的 activity.so 创建一个加载动画我使用了以下代码:
private void startCountAnimation() {
animator = ValueAnimator.ofInt(1000, 9000);
animator.setDuration(500);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.addUpdateListener((animation) -> {
tvCost.setText(animation.getAnimatedValue().toString());
});
animator.start();
}
这将计算 1000 到 9000。但我想在计算时使用货币格式。所以我希望结果显示为 1,000 到 9,000。
像这样格式化数字:
tvCost.setText(String.format("%10.0f", animation.getAnimatedValue()));
或本地货币:
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String currency = formatter.format(animation.getAnimatedValue());
tvCost.setText(currency);