动画加载... textview不断

时间:2016-08-25 05:01:52

标签: android

我试图为" Loading ..."的三个点设置动画。 textview如下,

Handler handler = new Handler();

        for (int i = 100; i <= 3500; i =i+100) {
            final int finalI = i;
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if(finalI %300 == 0){
                        loadigText.setText("Loading.");
                    }else if(finalI %200 == 0){
                        loadigText.setText("Loading..");
                    }else if(finalI %100 == 0){
                        loadigText.setText("Loading...");
                    }
                }
            }, i);

问题是,  我无法无限制地动画,直到对话框可见。  我无法降低三点动画的速度,

我怎样才能解决这个问题

1 个答案:

答案 0 :(得分:5)

示例:

 final Handler handler = new Handler();
        Runnable runnable = new Runnable() {

            int count = 0;

            @Override
            public void run() {
                count++;

                if (count == 1)
                {
                    textView.setText("Loading.");
                }
                else if (count == 2)
                {
                    textView.setText("Loading..");
                }
                else if (count == 3)
                {
                    textView.setText("Loading...");
                }

                if (count == 3)
                    count = 0;

                handler.postDelayed(this, 2 * 1000);
            }
        };
        handler.postDelayed(runnable, 1 * 1000);