2013-10-27 7 views
8

मैं टुकड़ों को प्रतिस्थापित करने के लिए एक कस्टम एनीमेशन का उपयोग कर रहा हूं, और एनीमेशन शुरू होने पर एनीमेशन शुरू होने पर सक्षम होने पर मैं कुछ बटन अक्षम करना चाहता हूं। मैं यह कैसे कर सकता हूँ?सेट से पहले और बाद में FragmentTransactionCustomAnimation कॉलबैक

उत्तर

25

मैं सुझाव दूंगा कि कुछ बेस क्लास बनाना है कि आपके सभी 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() बटन सक्षम करने के लिए: उदाहरण के लिए।

+2

यह स्लाइड या विस्फोट जैसे भौतिक संक्रमणों के साथ काम नहीं करता है क्योंकि 'एनिम' हमेशा शून्य होता है। – Servus7

संबंधित मुद्दे