有没有办法从上到下逐步显示ImageView, 像这样:
抱歉蹩脚的动画。
答案 0 :(得分:26)
我对android动画并不是很熟悉,但是一种(一种小的hackish)方式是将图像包装在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);
}
}