애니메이션을 중지하는 방법(취소()가 작동하지 않음)
실행 중인 번역 애니메이션을 중지해야 합니다..cancel()
의 방법Animation
효과가 없습니다. 어쨌든 애니메이션은 끝까지 진행됩니다.
실행 중인 애니메이션을 취소하려면 어떻게 해야 합니까?
불러clearAnimation()
어느 쪽이든View
니가 전화한startAnimation()
.
Android 4.4.4에서는 호출한 뷰에서 알파 페이딩 애니메이션을 중지할 수 있는 유일한 방법인 것 같습니다.View.animate().cancel()
(즉, 호출).cancel()
를 참조하십시오.
ICS 전후의 호환성을 위해 사용하는 코드는 다음과 같습니다.
public void stopAnimation(View v) {
v.clearAnimation();
if (canCancelAnimation()) {
v.animate().cancel();
}
}
다음 방법을 사용합니다.
/**
* Returns true if the API level supports canceling existing animations via the
* ViewPropertyAnimator, and false if it does not
* @return true if the API level supports canceling existing animations via the
* ViewPropertyAnimator, and false if it does not
*/
public static boolean canCancelAnimation() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
}
다음은 중지할 애니메이션입니다.
v.setAlpha(0f);
v.setVisibility(View.VISIBLE);
// Animate the content view to 100% opacity, and clear any animation listener set on the view.
v.animate()
.alpha(1f)
.setDuration(animationDuration)
.setListener(null);
애니메이션 청취자를 사용하는 경우 설정v.setAnimationListener(null)
모든 옵션에 다음 코드를 사용합니다.
v.getAnimation().cancel();
v.clearAnimation();
animation.setAnimationListener(null);
UI 스레드에서 .clearAnimation(); 메서드를 사용해야 합니다.
runOnUiThread(new Runnable() {
@Override
public void run() {
v.clearAnimation();
}
});
애니메이션을 중지하기 전에 변환 매트릭스를 가져오고 매트릭스 내용을 검사하여 찾고 있는 위치 값을 가져오는 것이 좋습니다.
여기 당신이 조사해야 할 api가 있습니다.
public boolean getTransformation (long currentTime, Transformation outTransformation)
public void getValues (float[] values)
예를 들어 (일부 유사 코드).테스트하지 않았습니다):
Transformation outTransformation = new Transformation();
myAnimation.getTransformation(currentTime, outTransformation);
Matrix transformationMatrix = outTransformation.getMatrix();
float[] matrixValues = new float[9];
transformationMatrix.getValues(matrixValues);
float transX = matrixValues[Matrix.MTRANS_X];
float transY = matrixValues[Matrix.MTRANS_Y];
메서드 setAnimation(null)을 사용하여 애니메이션을 중지합니다. 이 메서드는 View.java에서 공용 메서드로 노출되며 대화형 UI 구성 요소(버튼, 텍스트 필드 등)를 만드는 데 사용되는 모든 위젯의 기본 클래스입니다./** * Sets the next animation to play for this view. * If you want the animation to play immediately, use * {@link #startAnimation(android.view.animation.Animation)} instead. * This method provides allows fine-grained * control over the start time and invalidation, but you * must make sure that 1) the animation has a start time set, and * 2) the view's parent (which controls animations on its children) * will be invalidated when the animation is supposed to * start. * * @param animation The next animation, or null. */ public void setAnimation(Animation animation)
애니메이션을 중지하려면 아무 것도 하지 않는 객체 Animator를 설정할 수 있습니다.
먼저 수동으로 뒤집으면 왼쪽에서 오른쪽으로 애니메이션이 표시됩니다.
flipper.setInAnimation(leftIn);
flipper.setOutAnimation(rightOut);
자동 플립으로 전환할 때는 애니메이션이 없습니다.
flipper.setInAnimation(doNothing);
flipper.setOutAnimation(doNothing);
doNothing = ObjectAnimator.ofFloat(flipper, "x", 0f, 0f).setDuration(flipperSwipingDuration);
먼저 애니메이터 또는 애니메이터 세트와 관련된 모든 수신기를 제거합니다.그런 다음 애니메이터 또는 애니메이터 세트를 취소합니다.
inwardAnimationSet.removeAllListeners()
inwardAnimationSet.cancel()
다음 방법을 사용합니다.
// start animation
TranslateAnimation anim = new TranslateAnimation( 0, 100 , 0, 100);
anim.setDuration(1000);
anim.setFillAfter( true );
view.startAnimation(anim);
// end animation or cancel that
view.getAnimation().cancel();
view.clearAnimation();
취소하다, 취소하다, 취소하다, 취소하다, 취소하다, 취소하다, 취소함
애니메이션을 취소합니다.애니메이션을 취소하면 애니메이션 수신기가 호출되어(설정된 경우) 애니메이션 종료를 알립니다.애니메이션을 수동으로 취소하는 경우 애니메이션을 다시 시작하기 전에 reset()을 호출해야 합니다.
애니메이션 지우기()
이 보기에 대한 애니메이션을 취소합니다.
모든 것을 다 겪은 후에 아무것도 효과가 없었습니다.제가 보기에 여러 애니메이션을 적용했기 때문에.그래서 아래는 저에게 효과가 있었던 코드입니다.페이드 인 및 페이드 아웃이 계속되는 애니메이션 시작
val mAnimationSet = AnimatorSet()
private fun performFadeAnimation() {
val fadeOut: ObjectAnimator = ObjectAnimator.ofFloat(clScanPage, "alpha", 1f, 0f)
fadeOut.duration = 1000
val fadeIn: ObjectAnimator = ObjectAnimator.ofFloat(clScanPage, "alpha", 0f, 1f)
fadeIn.duration = 1000
mAnimationSet.play(fadeIn).after(fadeOut)
mAnimationSet.addListener(animationListener)
mAnimationSet.start()
}
지속적으로 루프인 애니메이션 청취자
private val animationListener=object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
super.onAnimationEnd(animation)
mAnimationSet.start()
}
}
반복적으로 진행되는 애니메이션을 막기 위해서입니다.저는 다음과 같이 했습니다.
private fun stopAnimation() {
mAnimationSet.removeAllListeners()
}
다른 답변에서 언급하지 않았기 때문에 다음을 사용하여 애니메이션을 쉽게 중지할 수 있습니다.ValueAnimator
의cancel()
.
ValueAnimator
애니메이션 제작에 매우 강력합니다.다음은 다음을 사용하여 번역 애니메이션을 만드는 샘플 코드입니다.ValueAnimator
:
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 5f);
int mDuration = 5000; //in millis
valueAnimator.setDuration(mDuration);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// Update your view's x or y coordinate
}
});
valueAnimator.start();
그런 다음 전화를 걸어 애니메이션을 중지합니다.
valueAnimator.cancel()`
언급URL : https://stackoverflow.com/questions/4112599/how-to-stop-an-animation-cancel-does-not-work
'programing' 카테고리의 다른 글
인덱스/고유 필드에서 쿼리할 때 MySQL "LIMIT 1"을 사용하는 포인트가 있습니까? (0) | 2023.07.25 |
---|---|
각도 2: 양식이 연결되지 않아 양식 제출이 취소되었습니다. (0) | 2023.07.25 |
RecyclerView로 무한 목록을 구현하는 방법은 무엇입니까? (0) | 2023.07.25 |
MariaDB 주 시작 날짜 & 주 번호 1 ~ 52 (0) | 2023.07.25 |
자바스크립트에서 비동기 호출을 동기 함수에서 기다리는 방법은 무엇입니까? (0) | 2023.07.25 |