有没有办法从上到下逐步显示一个ImageView, 像这样:
对不起,糟糕的动画。
最佳答案
我不是很熟悉 android 动画,但是一个(有点老套)的方法是将图像包装在 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);
}
}
关于android - 如何从上到下逐渐向下显示ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12127476/