仿支付宝金额滚动代码

啥也不说了,直接来码

public class TimerTestActivity extends Activity {

    private TextView txt;

    private Handler handler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txt = (TextView) findViewById(R.id.txt);
        txt.setText("0.00");
        // txt.setText("0");
        startTimer();
    }

    private void startTimer() {
        handler.removeCallbacks(run);
        handler.postDelayed(run, 50);
    }

    private Runnable run = new Runnable() {

        @Override
        public void run() {
            String str;
            if (txt.getText().toString().indexOf(",") >= 0) {
                str = txt.getText().toString().replace(",", "");
            } else {
                str = txt.getText().toString();
            }
            double s = Double.parseDouble(str);
            double trueS = 7676.87;
            double i = 0;
            if (trueS > 99999) {
                i = s + 42131.12;
            } else if (trueS > 9999) {
                i = s + 4213.21;
            } else if (trueS > 999) {
                i = s + 402.12;
            } else if (trueS > 99) {
                i = s + 41.21;
            } else {
                i = s + 4.11;
            }

            if (i < (trueS - trueS / 10)) {

                double d = Double.parseDouble(String.format("%.2f", i));

                String strI = String.valueOf(d);

                if (strI.length() <= 6) {
                    txt.setText(strI);
                } else if (strI.length() > 6 && strI.length() <= 9) {
                    txt.setText(strI.substring(0, strI.length() - 6) + ","
                            + strI.substring(strI.length() - 6));
                } else {
                    txt.setText(strI.substring(0, strI.length() - 9)
                            + ","
                            + strI.substring(strI.length() - 9,
                                    strI.length() - 6) + ","
                            + strI.substring(strI.length() - 6));
                }

            } else {

                String stt = "7676.87";

                if (stt.length() <= 6) {
                    txt.setText(stt);
                } else if (stt.length() > 6 && stt.length() <= 9) {
                    txt.setText(stt.substring(0, stt.length() - 6) + ","
                            + stt.substring(stt.length() - 6));
                } else {
                    txt.setText(stt.substring(0, stt.length() - 9) + ","
                            + stt.substring(stt.length() - 9, stt.length() - 6)
                            + "," + stt.substring(stt.length() - 6));
                }

            }

            if (i < trueS) {
                handler.postDelayed(run, 50);
            }

        }
    };

}


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值