Animation:

android:duration="1000" android:fillBefore="true" android:fromXScale="1.0" android:fromYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="0" android:toXScale="0.9" android:interpolator="@android:anim/decelerate_interpolator" android:repeatCount="infinite" android:toYScale="0.9" /> Animation anim= AnimationUtils.loadAnimation(getContext(),R.anim.clickbutton); 

The animation works, it works all the time, what you need, but there is such a nuance: I chose R.id.b1: the animation started and works, I chose R.id.b2: the animation started but also on R.id.b1: the animation continues to be performed, and need to stop

  rootViewB = inflater.inflate(R.layout.fragment2, container, false); for (int index = 0; index < buttonIds.length; index++) { arr_imageB[index] = (ImageView) rootViewB.findViewById(buttonIds[index]); } for (int j = 0; j < arr_imageB.length; j++) { arr_imageB[j].setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { //запускаю анимацию v.startAnimation(anim); switch (v.getId()) { case R.id.b1: { stopPlayerIfNeeded(); playSample(soundsRawResIds[0]); } break; case R.id.b2: { stopPlayerIfNeeded(); playSample(soundsRawResIds[1]); } break; case R.id.b3: { stopPlayerIfNeeded(); playSample(soundsRawResIds[2]); } break; case R.id.b4: { stopPlayerIfNeeded(); playSample(soundsRawResIds[3]); } break; case R.id.b5: { stopPlayerIfNeeded(); playSample(soundsRawResIds[4]); } break; case R.id.b6: { stopPlayerIfNeeded(); playSample(soundsRawResIds[5]); } break; case R.id.b7: { stopPlayerIfNeeded(); playSample(soundsRawResIds[6]); } break; } return false; } }); } return rootViewB; } } 

// here I start the melody and check for the restart of the melody

  stopPlayerIfNeeded(); playSample(soundsRawResIds[0]); 

about v.clearAnimation (); I heard only how to apply to my code

    1 answer 1

    Try this:

     for (int index = 0; index < buttonIds.length; index++) { arr_imageB[index].clearAnimation(); }