2011-03-05 14 views
6

मेरे पास एक गतिविधि थी (होम एक्टिविटी कहें) और जब मैं अपनी होमएक्टिविटी से एक नई गतिविधि (अगली एक्टिविटी कहता हूं) शुरू करता हूं, तो मैं इसे एनीमेशन प्रभाव देना चाहता हूं जैसे इसे नीचे से दिखाना। एंड्रॉइड में यह संभव है?एंड्रॉइड में एनीमेशन

उत्तर

2

आप अपने इरादे में Intent.FLAG_ACTIVITY_NO_ANIMATION ध्वज के साथ डिफ़ॉल्ट एनीमेशन (दाईं ओर से स्लाइड) को रोक सकते हैं।

यानी .:

Intent myIntent = new Intent(context, MyActivity.class); 
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
context.startActivity(myIntent); 

तो अपनी गतिविधि में तो आप बस अपने खुद के एनीमेशन निर्दिष्ट करना होगा।

6

startActivity पर कॉल करने के बाद, overridePendingTransition पर आईडी के एक्सएमएल परिभाषित एनिमेशन के साथ कॉल करें, एक गतिविधि से बाहर निकलने के लिए, एक प्रवेश करने के लिए। इस विधि के लिए दस्तावेज़ देखें here

1
TopListActivity topList; 
Vector<BitmapDrawable> images; 
int count = 0; 
public AnimationAlphaTimer(TopListActivity _topList) 
{ 
    this.topList = _topList; 

    this.images = new Vector<BitmapDrawable>(); 
    for (int i = 0; ; i++) { 
    // LOAD IMAGES HERE 
    } 

    if (this.images.size() > 0) { 
    this.topList.slide_0.setBackgroundDrawable(this.images.get(0)); 

    if (this.images.size() > 1) { 
     this.topList.slide_1.setBackgroundDrawable(this.images.get(1)); 
    } 
    } 

    this.count = 1; 
} 

public void launch() 
{ 
    if (this.images.size() >= 2) { 
    (new Timer(false)).schedule(this, 100); 
    } 
} 

@Override 
public void run() 
{ 
    this.doit(); 
    this.cancel(); 
} 

private void doit() 
{ 
    if ((this.count % 2) == 0) { 
    AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f); 
    animation.setStartOffset(3000); 
    animation.setDuration(3000); 
    animation.setFillAfter(true); 
    animation.setAnimationListener(this); 

    this.topList.slide_1.startAnimation(animation); 
    } else { 
    AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f); 
    animation.setStartOffset(3000); 
    animation.setDuration(3000); 
    animation.setFillAfter(true); 
    animation.setAnimationListener(this); 

    this.topList.slide_1.startAnimation(animation); 
    } 
} 

public void onAnimationEnd(Animation animation) 
{ 
    if ((this.count % 2) == 0) { 
    this.topList.slide_1.setBackgroundDrawable(
     this.images.get((this.count + 1) % (this.images.size())) 
    ); 
    } else { 
    this.topList.slide_0.setBackgroundDrawable(
     this.images.get((this.count + 1) % (this.images.size())) 
    ); 
    } 

    this.count++; 
    this.doit(); 
} 
public void onAnimationRepeat(Animation animation) { 
} 
public void onAnimationStart(Animation animation) { 
}} 

यह कोशिश करें कि मुझे लगता है कि यह काम करेगा।

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