2010-10-03 15 views
5

Özel içeriğimi göstermek için özel bir bağdaştırıcı kullanan bir liste görünümüm var. Onun düzeni aşağıdaki gibidir.İçeriği genişletmek/daraltmak için bir ListView'e animasyon ekleme

<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>  

Ben listview sadece gizli itemtext tutarak itemimage ve madde açıklaması kimlikleri ile görünümü gösterdi istiyorum. Fikir, öğenin her bir öğesinde, o öğeyi genişletmek için öğe metni içeriğini gösterecek şekilde bir onclicklistener'a sahip olmaktır. Her bir öğeyi genişletmek/daraltmak için Tweening animasyonunu kullanmam gerektiğini biliyorum, ancak bunu nasıl yapacağımı anlayamıyorum.

Bana yardım eden var mı? Daha fazla kod snippet'lerine ihtiyacınız varsa, sormaya çekinmeyin.

Şimdiden teşekkürler.

+0

Merhaba, sonunda anladın mı? Çözüme ilgi duyarım. – dragoon

cevap

7

Bunu yapmak için, kenar boşluğunu negatif değerlerle canlandıran ve öğeyi yok eden bir Animasyon sınıfı oluşturdum.

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(); 
    } 
} 
} 

Ben post

0

Udinic en çözümünü çalıştı blogumda bu animasyon için bütün bir örnek uygulaması var, ama nihayet bu alternatifi seçti:

animasyon şöyle

res/anim/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> 

bir imate ListView uygulaması:

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); 
} 

Örnek benim ListView animasyon çağrıları (veya herhangi Görünüm çocuk sınıfı): Benim KitKat telefonda

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

çalışıyor.