视图背景的动画变化不顺利

Animate change of view background not happening smoothly

我正在尝试为 activity 的背景制作动画 我所做的是

 ImageView image = (ImageView) findViewById(R.id.toggle_image);
    final TransitionDrawable td = new TransitionDrawable( new Drawable[] {
            getResources().getDrawable(R.drawable.welcomeimagetoggle1),
            getResources().getDrawable(R.drawable.welcomeimagetoggle2)
    });

    image .setImageDrawable(td);
    td.startTransition(3000);
    td.reverseTransition(3000);

    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            //Do something after 100ms
            td.startTransition(3000);
            td.reverseTransition(3000);
            handler.postDelayed(this, 3000);
        }
    }, 3000);

它工作正常,但问题是当计时器结束时发生的变化是平滑的,突然移动。我怎样才能避免这种情况?

我认为您应该改用 this library (DexMovingImageView)
它提供了一些很酷的过渡(查看他们的演示)。在您的情况下,使用包含多个图像的 DexCrossFadeImageView。
不要忘记让 activity 的 window 背景对 avoid overdraw.

透明

更新:关于填充,检查scaletype。
关于动画,这里是 KenBurnsView (ImageView animated by Ken Burns effect), Motion (ImageView with a parallax effect that reacts to the device's tilt) and finally LoyalNativeSlider(带有许多很酷的动画的图像滑块)。

希望这对您有所帮助!