2012-08-26 6 views

risposta

19

Non ho molta familiarità con le animazioni di Android, ma uno (un po 'di hacker) è di avvolgere l'immagine in un ClipDrawable e di animare il suo valore level. Per esempio:

<ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/clip_source" /> 

Dove clip_source è un disegnabile:

<?xml version="1.0" encoding="utf-8"?> 
<clip xmlns:android="http://schemas.android.com/apk/res/android" 
    android:clipOrientation="vertical" 
    android:drawable="@drawable/your_own_drawable" 
    android:gravity="bottom" /> 

Poi nel codice si avrebbe:

// a field in your class 
private int mLevel = 0; 

ImageView img = (ImageView) findViewById(R.id.imageView1); 
mImageDrawable = (ClipDrawable) img.getDrawable(); 
mImageDrawable.setLevel(0); 
mHandler.post(animateImage); 

Il animateImage è un oggetto Runnable:

private Runnable animateImage = new Runnable() { 

     @Override 
     public void run() { 
      doTheAnimation(); 
     } 
    }; 

e il metodo doTheAnimation:

private void doTheAnimation() { 
    mLevel += 1000; 
    mImageDrawable.setLevel(mLevel); 
    if (mLevel <= 10000) { 
     mHandler.postDelayed(animateImage, 50); 
    } else { 
     mHandler.removeCallbacks(animateImage); 
    } 
} 
+0

Interessante! Che cosa è mHandler in questo caso? – ibiza

+0

@ibiza È un'istanza di 'Handler',' Handler mHandler = new Handler(); '. – Luksprog

+0

Non riesco a essere in grado di far funzionare questo metodo, vedo sempre l'immagine intera – ibiza

Problemi correlati