2010-10-03 8 views
5

मेरे पास एक सूची दृश्य है जो मेरी कस्टम सामग्री दिखाने के लिए कस्टम एडाप्टर का उपयोग करता है। इसका लेआउट निम्नलिखित है।सामग्री को विस्तृत/संक्षिप्त करने के लिए किसी सूची दृश्य में एनीमेशन जोड़ना

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"> 
     <ImageView 
      android:id="@+id/itemimage" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="5" 
      android:scaleType="fitCenter"/> 
     <TextView 
      android:id="@+id/itemdescription" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="10dp" 
      android:textSize="16sp" 
      android:layout_weight="1"/> 
    </LinearLayout>  
    <TextView 
      android:id="@+id/itemtext" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="TEXT CONTENT" 
      android:layout_weight="1"/> 
</LinearLayout>  

मैं चाहूँगा कि सूचीदृश्य केवल आईडी itemimage और आइटम वर्णन के साथ दृश्य से पता चला है, itemtext छिपा रखे हुए हैं। विचार उस आइटम का विस्तार करने के लिए सूची के प्रत्येक आइटम पर ऑनक्लिकलिस्टर होना है, इसलिए यह आइटम टेक्स्ट सामग्री दिखाता है। मुझे पता है कि मुझे प्रत्येक आइटम को विस्तार/संक्षिप्त करने के लिए ट्विनिंग एनीमेशन का उपयोग करना चाहिए, लेकिन मैं यह नहीं समझ सकता कि इसे कैसे किया जाए।

क्या कोई मुझे इसके साथ मदद कर सकता है? यदि आपको अधिक कोड स्निपेट की आवश्यकता है, तो पूछने के लिए स्वतंत्र महसूस करें।

अग्रिम धन्यवाद।

+0

हाय, क्या आपने अंततः इसे समझ लिया? मुझे समाधान में दिलचस्पी होगी। – dragoon

उत्तर

7

ऐसा करने के लिए, मैंने एक एनीमेशन क्लास बनाया, जो मार्जिन को नकारात्मक मानों में एनिमेट करता है, जिससे आइटम गायब हो जाता है।

एनीमेशन इस तरह दिखता है:

public class ExpandAnimation extends Animation { 
@Override 
protected void applyTransformation(float interpolatedTime, Transformation t) { 
    super.applyTransformation(interpolatedTime, t); 

    if (interpolatedTime < 1.0f) { 

     // Calculating the new bottom margin, and setting it 
     mViewLayoutParams.bottomMargin = mMarginStart 
       + (int) ((mMarginEnd - mMarginStart) * interpolatedTime); 

     // Invalidating the layout, making us seeing the changes we made 
     mAnimatedView.requestLayout(); 
    } 
} 
} 

मैं अपने ब्लॉग post

0

Udinic के समाधान की कोशिश की पर इस एनीमेशन के लिए एक पूरी उदाहरण ऐप्लिकेशन है, लेकिन अंत में यह विकल्प चुना है:

रेस/एनिम/scale_down.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 
<scale 
    android:duration="700" 
    android:fromXScale="1.0" 
    android:fromYScale="1.0" 
    android:pivotX="50%" 
    android:pivotY="0%" 
    android:toXScale="1.0" 
    android:toYScale="0.0" /> 
</set> 

एन Imate ListView कार्यान्वयन:

protected void animateView(final View v, final int animResId, final int endVisibility){ 
    Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), 
      animResId); 
    anim.setAnimationListener(new Animation.AnimationListener() { 
     public void onAnimationStart(Animation animation) { 
      v.setVisibility(View.VISIBLE); 
     } 
     public void onAnimationEnd(Animation animation) { 
      v.setVisibility(endVisibility); 
     } 
     public void onAnimationRepeat(Animation animation) {} 
    }); 
    v.startAnimation(anim); 
} 

उदाहरण मेरी ListView चेतन करने के लिए कॉल (या किसी भी दृश्य बच्चे वर्ग):

animateView(listView1, R.anim.scale_down, View.GONE); 
animateView(listView1, R.anim.scale_up, View.VISIBLE); 

यह मेरी किटकैट फोन पर काम कर रहा है।

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