2012-01-17 15 views
10

मैं सूची दृश्य के आइटम एनिमेट करना चाहता हूं। वर्तमान में जब भी नए आइटम जोड़े जाते हैं तो मैं सूची आइटम पर संक्रमण एनीमेशन लागू कर रहा हूं। लेकिन यह वह एनीमेशन नहीं है जिसे मैं प्राप्त करना चाहता हूं। मैं चाहता हूं कि जब उस समय सूची दृश्य में कोई नया आइटम जोड़ा जाए तो संपूर्ण सूची दृश्य नए जोड़े गए आइटम के लिए रास्ता बनाने के लिए एक स्थान को नीचे ले जायेगा।एंड्रॉइड में एक सूची दृश्य में एनीमेशन जोड़ना

वर्तमान कोड मैं का उपयोग कर रहा है:

set = new AnimationSet(true); 

    animation = new AlphaAnimation(0.0f, 1.0f); 
    animation.setDuration(50); 
    set.addAnimation(animation); 

    animation = new TranslateAnimation(
     Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, 
     Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f 
    ); 
    animation.setDuration(150); 
    set.addAnimation(animation); 

    LayoutAnimationController controller = new LayoutAnimationController(set, 1.0f); 
    l.setLayoutAnimation(controller); 
    l.setAdapter(listAdaptor); 

और फिर, जबकि बटन के माध्यम से जोड़ने के आइटम

l.startLayoutAnimation(); 

किसी भी अन्य सुझाव onclick ऐसे एनीमेशन प्राप्त करने के लिए।

उत्तर

14

मुझे इसका समाधान मिला। मैं अपने कस्टम एडाप्टर की getView विधि में प्रत्येक जोड़ा तत्व एनिमेट करता हूं।

public View getView(int position, View convertView, ViewGroup parent) { 

     View v = convertView; 

     if (v == null) { 
      LayoutInflater vi = (LayoutInflater) getActivity() 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = vi.inflate(R.layout.simple_list_item_1, null); 
     } 

     ListData o = list.get(position); 
     TextView tt = (TextView) v.findViewById(R.id.toptext); 

     tt.setText(o.content); 

     Log.d("ListTest", "Position : "+position); 
     if(flag == false) { 
     Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_top_to_bottom); 
     v.startAnimation(animation);} 
     return v; 
    } 

और इस तरह एनीमेशन हासिल किया जैसा मैंने कहा था।

+0

मुझे 'R.anim.slide_top_to_bottom' एनी में त्रुटि मिल रही है, हल नहीं किया जा सकता है या कोई फ़ील्ड नहीं है – Nishant

+0

क्या आपने एनिम फ़ोल्डर में xml जोड़ा था? – ASH

+0

क्या आप उस फ़ाइल के लिए कोड नहीं दे सकते? – Nishant

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