20

有没有办法从上到下逐步显示 ImageView,如下所示:

在此处输入图像描述

对不起,糟糕的动画。

4

1 回答 1

34

我对android动画不是很熟悉,但是一种(有点hackish)的方法是将图像包装在 a 中并为其值ClipDrawable设置动画。level例如:

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

clip_source可绘制对象在哪里:

<?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" />

然后在代码中您将拥有:

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

animateImage一个Runnable对象:

private Runnable animateImage = new Runnable() {

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

doTheAnimation方法:

private void doTheAnimation() {
    mLevel += 1000;
    mImageDrawable.setLevel(mLevel);
    if (mLevel <= 10000) {
        mHandler.postDelayed(animateImage, 50);
    } else {
        mHandler.removeCallbacks(animateImage);
    }
}
于 2012-08-26T06:06:39.527 回答