Cómo mostrar un ImageView progresivamente hacia abajo de arriba a abajo
Frecuentes
Visto 9,134 veces
20
is there a way to display an ImageView progressively from top to down, like this:
Sorry for the crappy animation.
1 Respuestas
34
I'm not very familiar with android animations, but one(a little hackish) way is to wrap the image in a ClipDrawable
y animar su level
valor. Por ejemplo:
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/clip_source" />
Dónde clip_source
is a drawable:
<?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" />
Then in code you would have:
// 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);
Programas de animateImage
es un Runnable
:
private Runnable animateImage = new Runnable() {
@Override
public void run() {
doTheAnimation();
}
};
y el doTheAnimation
método:
private void doTheAnimation() {
mLevel += 1000;
mImageDrawable.setLevel(mLevel);
if (mLevel <= 10000) {
mHandler.postDelayed(animateImage, 50);
} else {
mHandler.removeCallbacks(animateImage);
}
}
Respondido 26 ago 12, 21:08
Interesting! What is mHandler in that case? - Marrón
@ibiza It's a Handler
ejemplo, Handler mHandler = new Handler();
. - usuario
I can't seem to be able to make this method work, I always see the full image - Marrón
@ibiza Some parts from my original code didn't show up. See if it works now. - usuario
got it, changed the android:gravity="bottom" of the xml drawable to android:gravity="top" - Marrón
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android android-imageview or haz tu propia pregunta.
Quiere que el
ImageView
to animate that way by itself? Or you want to do it as the user does something? - usernot sure what the difference is but I would say by itself - Bruno