如何从上到下逐渐显示ImageView [英] How to display an ImageView progressively down from top to bottom
本文介绍了如何从上到下逐渐显示ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以从上到下逐步显示ImageView, 像这样:
is there a way to display an ImageView progressively from top to down, like this:
对不起,动画animation脚.
Sorry for the crappy animation.
推荐答案
我对android动画不是很熟悉,但是一种(有点怪异)的方法是将图像包装在ClipDrawable
中并为其
I'm not very familiar with android animations, but one(a little hackish) way is to wrap the image in a ClipDrawable
and animate its level
value. For example:
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/clip_source" />
clip_source
是可绘制对象的地方:
Where 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);
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文