2012-06-29 18 views
13

क्या Animation एक आधे सेकेंड के लिए रुकने का कोई तरीका है?एनीमेशन के भीतर देरी (अनुवादएनीमेशन)

मैं TranslateAnimation API का उपयोग कर एक अनंत एनीमेशन बनाने की कोशिश कर रहा हूं। इसलिए, मैं RepeatCountInfinite के रूप में उपयोग करता हूं। मैंने यह भी देखा कि setStartOffset(...) विधि है जो केस को कवर करती है जब मैं एनीमेशन शुरू करने में देरी करना चाहता हूं। हालांकि, मुझे प्रत्येक 'पुनरारंभ' से पहले देरी करने का कोई तरीका नहीं मिल रहा है। चूंकि एनीमेशन असीमित बार होने वाला है, हर बार जब एनीमेशन पुनरारंभ होता है तो मुझे देरी डालना पड़ता है।

कोई विचार?

धन्यवाद !!

पहले लेआउट (main.xml) एक छवि के साथ हम चेतन चाहते हैं:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

अगला एक एनीमेशन है

+0

शायद इसे एक थ्रेड में डालने का प्रयास करें जो एनीमेशन शुरू करेगा, एक्स मात्रा के लिए सोएगा, फिर अनंत का उपयोग करने के बजाय एनीमेशन शुरू करें? – Guardanis

उत्तर

11

यहाँ एक उदाहरण है। Res/anim में रखा गया है और इसे anim_img.xml कहा जाता है। फ़ाइल में एंड्रॉइड के साथ अनुवाद एनीमेशन है: startOffset = "500" (मिलीसेक में)। यह ऑफ़सेट सेट करेगा, जिसका प्रयोग हर बार एनीमेशन शुरू होता है:

<?xml version="1.0" encoding="utf-8"?> 
<set> 

    <translate 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="1000" 
     android:fromXDelta="0%" 
     android:fromYDelta="0%" 
     android:toXDelta="0%" 
     android:toYDelta="100%" 
     android:zAdjustment="top" 
     android:repeatCount="infinite" 
     android:startOffset="500"/> 

</set> 

और अंतिम लेकिन कम से कम नहीं - गतिविधि।

public class StackOverflowActivity extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     ImageView iv_icon = (ImageView) findViewById(R.id.imageView1); 

     Animation a = AnimationUtils.loadAnimation(this, R.anim.anim_img); 
     a.setFillAfter(true); 
     a.reset(); 

     iv_icon.startAnimation(a); 
    } 
} 

चीयर्स, पॉल

+0

धन्यवाद! मैं कोशिश करूँगा और रिपोर्ट करूंगा कि क्या इस दृष्टिकोण ने काम किया है ... – ymotov

9

प्रत्येक पुनः आरंभ करने के बीच एक्स मिलीसेकंड का एक विराम के लक्ष्य को हासिल करने के लिए:: कौन सा एनीमेशन शुरू होता है

myAnimation.setAnimationListener(new AnimationListener(){ 

     @Override 
     public void onAnimationStart(Animation arg0) { 
     } 
     @Override 
     public void onAnimationEnd(Animation animation) { 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
      myAnimation.setStartOffset(x); 
     } 

    }); 
+0

यह बहुत अच्छा है, धन्यवाद! – nurxyz

0

myanimation.setStartDelay (int);

+0

आपको यह तरीका कहां मिला? – hrules6872

+1

@h_rules वह शायद 'setStartOffset (लंबा)' का अर्थ है। –

+2

इसे दृश्य पर बुलाया जाना चाहिए। । 'View.animate() setDuration (1000) .setStartDelay (500);' – Yurets