android - 如何从上到下逐渐向下显示ImageView

标签 android android-imageview

有没有办法从上到下逐步显示一个ImageView, 像这样:

enter image description here

对不起,糟糕的动画。

最佳答案

我不是很熟悉 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/

相关文章:

java - 在 Android 7 org.apache.http (Apache HttpClient 4.0) 中启用已弃用的密码套件后主机名不匹配

android - 拖动时跳转 ImageView。 getX() 和 getY() 值在跳跃

android - 放大图像以填充 Android 中的整个 ImageView

android - 将图像从 url 转换为位图

安卓相机 : data intent returns null

java - 如何通过 URL Android 在 ImageView 中设置图像

android - Android 浏览器中列表项后的行

android - 奇怪的 logcat 过滤器行为

android - "minSdkVersion"用于 InstantApp 支持?

android - 有没有办法判断 Google map fragment 中的相机何时停止移动?