是否有一种方法可以逐步从上到下显示一个ImageView,就像这样:
抱歉动画效果比较差。
我对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);
}
}
ImageView
自己以那种方式进行动画吗?还是你想在用户执行某些操作时才这样做? - user