8
저는 조각을 대체하기 위해 맞춤 애니메이션을 사용하고 있습니다. 애니메이션이 시작될 때 일부 버튼을 비활성화하고 애니메이션이 끝날 때 사용 가능하게하고 싶습니다. 어떻게해야합니까?setCustomAnimation 콜백 전후의 FragmentTransaction
저는 조각을 대체하기 위해 맞춤 애니메이션을 사용하고 있습니다. 애니메이션이 시작될 때 일부 버튼을 비활성화하고 애니메이션이 끝날 때 사용 가능하게하고 싶습니다. 어떻게해야합니까?setCustomAnimation 콜백 전후의 FragmentTransaction
내가 제안하는 것은 모든 Fragments
이 애니메이션 이벤트를 처리하기 위해 재정의 할 수있는 몇 가지 메서드를 정의하고 그 내에서 확장하는 기본 클래스를 만드는 것입니다. 그런 다음 onCreateAnimation()
(지원 라이브러리를 사용한다고 가정)을 재정 의하여 애니메이션 콜백에 대한 이벤트를 보냅니다.
protected void onAnimationStarted() {}
protected void onAnimationEnded() {}
protected void onAnimationRepeated() {}
@Override
public Animation onCreateAnimation (int transit, boolean enter, int nextAnim) {
//Check if the superclass already created the animation
Animation anim = super.onCreateAnimation(transit, enter, nextAnim);
//If not, and an animation is defined, load it now
if (anim == null && nextAnim != 0) {
anim = AnimationUtils.loadAnimation(getActivity(), nextAnim);
}
//If there is an animation for this fragment, add a listener.
if (anim != null) {
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart (Animation animation) {
onAnimationStarted();
}
@Override
public void onAnimationEnd (Animation animation) {
onAnimationEnded();
}
@Override
public void onAnimationRepeat (Animation animation) {
onAnimationRepeated();
}
});
}
return anim;
}
그런 다음 Fragment
서브 클래스, 단지 버튼을 비활성화 onAnimationStarted()
을 무시하고 onAnimationEnded()
이 버튼을 사용하려면 예를 들면 다음과 같습니다.
'anim'이 항상 null이기 때문에 슬라이드 또는 폭발과 같은 머티리얼 전환에서는 작동하지 않습니다. – Servus7