2010-07-21 7 views
34

मैं एक बहुत ही सरल अल्फा एनीमेशन करना चाहता हूं लेकिन मुझे वैध तरीका नहीं मिल रहा है।एंड्रॉइड अल्फा एनीमेशन fadeout faysout देरी के साथ

विचार की दृष्टि से अधिक इस एनीमेशन प्रदर्शन करने के लिए है:

  1. अल्फा 0 से 1 के 1 सेकंड
  2. पकड़ 5 सेकंड
  3. के लिए 1 पर अल्फा के
  4. 1 से 1 0 दूसरे के लिए अल्फा
  5. 5 सेकंड के लिए 0 पर अल्फा रखें। पर 1.

मैं कोशिश की है फिर

  • शुरुआत के रूप में एक AnimationSet साथ लागू करने के लिए है कि:

    AnimationSet animationSet = new AnimationSet(true); 
    
    Animation animation1 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_in); 
    animation1.setDuration(1000); 
    
    Animation animation2 = new AnimationUtils.loadAnimation(this, android.R.anim.fade_out); 
    animation2.setDuration(1000); 
    animation2.setStartOffset(5000); 
    
    Animation animation3 = new AlphaAnimation(0.0f, 0.0f); 
    animation3.setDuration(4000) 
    animation3.setStartOffset(6000); 
    
    animationSet.add(animation1); 
    animationSet.add(animation2); 
    animationSet.add(animation3); 
    

    आदि ..

    लेकिन यह seams कि तीसरे एनीमेशन एक मेस करना सभी अल्फा एनिमेशन के साथ, मुझे लगता है कि एंड्रॉइड इस प्रकार की एनीमेशन प्रबंधित करने के तरीके में एक आंतरिक असुविधा का कारण बनता है।

    कोई विचार?

    धन्यवाद।

  • +0

    क्या आप कृपया मुझे बता सकते हैं कि मेरा कोड अच्छा काम करता है या नहीं? और अगर उत्तर –

    उत्तर

    101

    मन में ठीक रखें इन 2 अंक इस


    • हल करने के लिए मैं 1 सेकंड के एक एनीमेशन की अवधि के साथ 5 सेकंड के बाद 1.0f to 0.0f चेतन चाहते हैं, यह एक साथ अंत में एक 1 सेकंड एनीमेशन है 5 सेकंड की रोकथाम।

      इस प्राप्त करने के लिए:

      1. setDuration(1000)
      2. setStartOffset(5000) (यह 5 सेकंड के बाद शुरू होगा) (यह एक 1 सेकंड की अवधि है)

    • आपको केवल 2 एनिमेशन की आवश्यकता है जो एल हमेशा के लिए ओओपी।

      animation1 = new AlphaAnimation(0.0f, 1.0f); 
          animation1.setDuration(1000); 
          animation1.setStartOffset(5000); 
      
          animation2 = new AlphaAnimation(1.0f, 0.0f); 
          animation2.setDuration(1000); 
          animation2.setStartOffset(5000); 
      
          textView.startAnimation(animation1); 
      
      :

      1. 5 सेकंड ठहराव और 1 सेकंड की अवधि

      2. 5 सेकंड ठहराव के साथ 1.0f to 0.0f और 1 सेकंड की अवधि


    और यहाँ के साथ 0.0f to 1.0f कोड है

    हालांकि हमेशा के लिए लूप करने के लिए मैं AnimationListener का उपयोग करूंगा क्योंकि repeatCount छोटी है:

    animation1 = new AlphaAnimation(0.0f, 1.0f); 
        animation1.setDuration(1000); 
        animation1.setStartOffset(5000); 
    
        //animation1 AnimationListener 
        animation1.setAnimationListener(new AnimationListener(){ 
    
         @Override 
         public void onAnimationEnd(Animation arg0) { 
          // start animation2 when animation1 ends (continue) 
          textView.startAnimation(animation2); 
         } 
    
         @Override 
         public void onAnimationRepeat(Animation arg0) { 
          // TODO Auto-generated method stub 
    
         } 
    
         @Override 
         public void onAnimationStart(Animation arg0) { 
          // TODO Auto-generated method stub 
    
         } 
    
        }); 
    
        animation2 = new AlphaAnimation(1.0f, 0.0f); 
        animation2.setDuration(1000); 
        animation2.setStartOffset(5000); 
    
        //animation2 AnimationListener 
        animation2.setAnimationListener(new AnimationListener(){ 
    
         @Override 
         public void onAnimationEnd(Animation arg0) { 
          // start animation1 when animation2 ends (repeat) 
          textView.startAnimation(animation1); 
         } 
    
         @Override 
         public void onAnimationRepeat(Animation arg0) { 
          // TODO Auto-generated method stub 
    
         } 
    
         @Override 
         public void onAnimationStart(Animation arg0) { 
          // TODO Auto-generated method stub 
    
         } 
    
        }); 
    
        textView.startAnimation(animation1); 
    
    +0

    सही उत्तर दें तो कृपया उत्तर स्वीकार करें! आपका बहुत बहुत धन्यवाद! – David

    +0

    अच्छी तरह से यह 5 सेकंड प्रतीक्षा करने के लिए उपयोग कर सकते हैं और फिर कुछ दिखा सकते हैं? handler.post देरी के लिए। – mehmet

    14

    इसका एक आसान समाधान है।

    मान लें कि आपका विचार राज्य में है। इसकी दृश्यता को एनिमेट करने के लिए:

    yourView.setVisibility(View.VISIBLE); 
    yourView.animate().alpha(1).setDuration(300); 
    

    उसी तरह से आप एनीमेशन श्रोताओं को जोड़ सकते हैं।

    यह स्केल और अनुवाद एनिमेशन के लिए भी काम करता है।

    +1

    बहुत अच्छा। धन्यवाद। – paakjis

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