Android animation does not repeat

后端 未结 23 1480
囚心锁ツ
囚心锁ツ 2020-11-27 14:01

I\'m trying to make simple animation that would repeat several times (or infinitely).
It seems that android:repeatCount does not work!
Here is my anim

23条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 14:23

    I solved this problem using thread.

    Button btn = (Button) findViewById(R.id.buttonpush);
        final TextView textview = (TextView) findViewById(R.id.hello);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textview.setText("...................");
                final Animation animationtest = AnimationUtils.loadAnimation(MainActivity.this, android.R.anim.slide_in_left);
                animationtest.setDuration(1000);
    
                final Handler handler = new Handler();
                Runnable runnable = new Runnable() {
                    public void run() {
                        handler.postDelayed(this, 1500);
                        textview.startAnimation(animationtest);
                    }
                };
                handler.postDelayed(runnable, 500); // start
                handler.removeCallbacks(runnable); //STOP Timer
    
            }
        });
    

提交回复
热议问题