现在的位置: 首页 > 编程语言 > 正文

仿支付宝金额滚动代码

2018年09月10日 编程语言 ⁄ 共 1565字 ⁄ 字号 评论关闭

啥也不说了,直接来码

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);
            }

        }
    };

}

抱歉!评论已关闭.