RollNum ,滚动数字
来源:互联网 发布:社区圈子源码 编辑:程序博客网 时间:2024/05/17 02:30
github源码下载
package com.oblivion.myapplication;import android.support.annotation.NonNull;import android.widget.TextView;import java.util.LinkedList;import java.util.Random;/** * author:Created by Oblivion on 2017/1/12. */public class NumAnim { //每秒刷新多少次 private static final int COUNTPERS = 100; public static void startAnim(TextView textV, @NonNull float num) { startAnim(textV, num, 500); } public static void startAnim(TextView textV, float num, long time) { if (num == 0) { textV.setText(NumUtil.NumberFormat(num, 2)); return; } Float[] nums = splitnum(num, (int) ((time / 1000f) * COUNTPERS)); Counter counter = new Counter(textV, nums, time); textV.removeCallbacks(counter); textV.post(counter); } private static Float[] splitnum(float num, int count) { Random random = new Random(); float numtemp = num; float sum = 0; LinkedList<Float> nums = new LinkedList<>(); nums.add(0f); while (true) { float nextFloat = NumUtil.NumberFormatFloat( (random.nextFloat() * num * 2f) / (float) count, 2); System.out.println("next:" + nextFloat); if (numtemp - nextFloat >= 0) { sum = NumUtil.NumberFormatFloat(sum + nextFloat, 2); nums.add(sum); numtemp -= nextFloat; } else { nums.add(num); return nums.toArray(new Float[0]); } } } static class Counter implements Runnable { private final TextView view; private Float[] nums; private long pertime; private int i = 0; Counter(TextView view, Float[] nums, long time) { this.view = view; this.nums = nums; this.pertime = time / nums.length; } @Override public void run() { if (i > nums.length - 1) { view.removeCallbacks(Counter.this); return; } view.setText(NumUtil.NumberFormat(nums[i++], 2)); view.removeCallbacks(Counter.this); view.postDelayed(Counter.this, pertime); } }}
package com.oblivion.myapplication;/** * author:Created by Oblivion on 2017/1/12. */public class NumUtil { /** * * @param f 传入的float值, * @param m 传入的执行时间 * @return */ public static String NumberFormat(float f,int m){ return String.format("%."+m+"f",f); } public static float NumberFormatFloat(float f,int m){ String strfloat = NumberFormat(f,m); return Float.parseFloat(strfloat); }}
1 0
- RollNum ,滚动数字
- 数字滚动
- js 数字滚动 动画
- android 数字滚动
- Android数字纵向滚动
- jquery数字滚动
- ScrollNumber 数字滚动
- 数字滚动效果
- 【特效】滚动的数字
- QT滚动数字
- jQuery实现数字滚动
- 数字滚动特效
- 滚动的数字
- 数字滚动抽奖的代码
- jQuery数字滚动展示效果
- [jQuery][插件][tgAnimationLabel]数字滚动
- cocos2d-x 滚动数字label
- JQ实现数字滚动显示
- Spark性能优化:数据倾斜调优
- [Audio Profile]L版本上music如何设置双卡铃声
- 【SSH网上商城项目实战02】基本增删查改、Service和Action的抽取以及使用注解替换xml
- Red Hat Enterprise Linux 7 root账号自动登陆
- Address already in use: JVM_Bind错误的解决
- RollNum ,滚动数字
- IMF spark 正则表达式 统计apache log 日志
- 你可能漏掉的知识点: onResumeFragments
- 恢复系统强制卸载MSDE
- Service入门(二)——bindService、unbindService
- node之第一个hello world
- C#时间类型 DateTime? 赋空值
- 异常的捕捉和抛出
- 字符串转化为整数