8

मेरे पास वर्तमान में एक काम कर रहे एंड्रॉइड प्रोग्राम है जो प्रोग्रामर रूप से एक लीनियरलाउट में दृश्य जोड़ता है। मैं उन विचारों को एनिमेटेड करना चाहता हूं और यह कैसे करना है यह जानने के लिए कोई अच्छा संसाधन नहीं मिल रहा है।एंड्रॉइड: LinearLayout addView एनिमेशन

क्या कोई मुझे सही दिशा में इंगित कर सकता है?

उत्तर

-2

आप व्यूफ्लिपर का उपयोग कर सकते हैं और वहां से एनिमेशन सेट कर सकते हैं, आप इस tutorial पर एक नज़र डाल सकते हैं। सौभाग्य।

7

यह एक बहुत पुरानी सवाल, लेकिन अभी भी दिलचस्प है: यदि आप उदाहरण के लिए विशेषता android:animateLayoutChanges="true"

उपयोग कर सकते हैं:

<LinearLayout 

       android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:animateLayoutChanges="true" 
       /> 
4

Scenes and Transitions API साथ किया जा सकता है।

फ्रेमवर्क हमें बॉक्स से बाहर तीन Transition प्रकार देता है: Fade, Slide और Explode, लेकिन आप भी और संक्रमण Visibility वर्ग का विस्तार अधिभावी उचित तरीकों के अपने कस्टम प्रकार बना सकते हैं।

तो, किसी भी ViewGroup होने, हम ऐसा कर सकते हैं:

viewGroup.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(final View v) { 
     Transition t = null; 
     if (i == 1) { 
      t = new Fade(); 
     } else if (i == 2) { 
      t = new Slide(Gravity.BOTTOM); 
     } else if (i == 3) { 
      t = TransitionInflater.from(v.getContext()) 
            .inflateTransition(R.transition.my_transition); 
     } 

     Button button = new Button(v.getContext()); 
     button.setText("My button " + i++); 

     TransitionManager.beginDelayedTransition(customLayout, t); 
     viewGroup.addView(button); 
    } 
}); 

my_transition.xml कहाँ पीछा कर रहा है:

enter image description here:

<?xml version="1.0" encoding="utf-8"?> 
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" 
       android:duration="3000" 
       android:interpolator="@android:interpolator/fast_out_slow_in"> 

    <fade/> 
    <slide android:slideEdge="bottom"/> 

</transitionSet> 

हम इस परिणाम मिल जाएगा

ध्यान दें, लेआउट में किए गए किसी भी बदलाव से पहले हमें TransitionManager.beginDelayedTransition() करना होगा (यानी। addView() से पहले कहा जाता है)। फिर ढांचा बाकी का ख्याल रखेगा।

वहाँ भी एक और अधिभार TransitionManager.beginDelayedTransition(ViewGroup), जहाँ आप क्या सटीक संक्रमण आप लागू किया जा करना चाहते हैं निर्दिष्ट करने की आवश्यकता नहीं है, और प्रणाली AutoTransition एनीमेशन, जो मूल रूप से नहीं हो पाती और एनिमेटेड दृश्य की सीमाओं बदल जाएगा प्रदर्शन करेंगे है।


अद्यतन टिप्पणी में बातचीत से योग अप

फ्रेमवर्क के TransitionManager एपीआई 19 से उपलब्ध है, और पूरी तरह से एपीआई 21 से समर्थित है (पूरी तरह से कह रही है मेरा मतलब द्वारा उदा Slide संक्रमण एपीआई 21 से उपलब्ध है)। हालांकि support package available है, लेकिन यह सभी कार्यक्षमता का बैकपोर्ट नहीं करता है। वैकल्पिक रूप से, आप TransitionsEverywhere लाइब्रेरी पर जा सकते हैं, जो एंड्रॉइड 4.0 तक सब कुछ बैकपोर्ट करता है।

+0

का उपयोग मैं इसे चाहता हूं जब मैं इस के लिए 'int (int i = 0; i

+0

'लूप' से पहले 'TransitionManager.beginDelayedTransition() 'रखें। – azizbekian

+0

मैं my_transition.xml को जोड़ने की कोशिश कर रहा हूं, मुझे ** @ एंड्रॉइड मिला है: इंटरपोलेटर/fast_out_slow_in को एपीआई स्तर 21 (वर्तमान मिनट 15 है) ** एंड्रॉइड पर: इंटरपोलेटर = "@ एंड्रॉइड: इंटरपोलेटर/fast_out_slow_in" ' –

1

प्रयास करें

1. रेखीय लेआउट

linearLayout.addView(customView); 

2 को देखने जोड़ें। सही दृश्य

Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_up); 
customView.startAnimation(animation); 

जोड़ने आप विचारों एक के बाद एक चेतन करना चाहते हैं के बाद slide_up.xmlres/anim फ़ोल्डर में

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillAfter="true"> 

    <translate 
    android:duration="500" 
    android:fromYDelta="100%" 
    android:toYDelta="0%" /> 
</set> 

3. लागू एनीमेशन जोड़ कर निम्नलिखित लाइनों

new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      linearLayout.addView(customView); 
      Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_up); 
      customView.startAnimation(animation); 
     } 
}, 500); 
+0

मैं एक के बाद एक स्लाइड करना चाहता हूं, लेकिन यह एक साथ सभी customeview स्लाइड। मेरा 'linearLayout.addView (customView); 'लूप में जोड़ें –

+0

आप देरी जोड़ सकते हैं, मैंने जवाब अपडेट किया है। – Pehlaj

+0

हम हैंडलर का सही उपयोग करके इसे प्राप्त कर सकते हैं – Pehlaj