마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 setRepeatCount 적용하기

0 추천

setRepeatCount가 적용안되는대 왜그러는지 아시는분 도와주세요ㅜㅜ

xml에 넣어서 테스트 해보니 동작하는대 java에서는 동작을 안합니다.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:ignore="ExtraText"
    android:fillAfter="false">

    <translate
        android:fromXDelta="-300%"
        android:toXDelta="300%"
        />
</set>

 

public class MainActivity extends AppCompatActivity {

    ImageView ball;
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ball = (ImageView) findViewById(R.id.ball);

        btn = (Button) findViewById(R.id.btn);

        final Animation ball_ani = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.test);
        ball_ani.setDuration(1000);
        ball_ani.setRepeatCount(3);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ball.startAnimation(ball_ani);
            }
        });

    }
}
익명사용자 님이 2017년 12월 28일 질문
2017년 12월 28일 수정

1개의 답변

0 추천

Load된 animation이 AnimationSet이여서 RepeatCount는 무시됩니다.

다음처럼 포함된 Animation에 직접 설정하면 반복 동작합니다.

 

final AnimationSet ball_ani = (AnimationSet)AnimationUtils.loadAnimation(getApplicationContext(), R.anim.test);
ball_ani.setDuration(1000);
ball_ani.getAnimations().get(0).setRepeatCount(3);

 

디자이너정 (42,810 포인트) 님이 2017년 12월 28일 답변
감사합니다. 알려주신대로 하니 바로 동작하내요^^
...