用于“淡入”图像的Alpha动画?

时间:2012-05-06 07:41:53

标签: android

我有一张我想慢慢淡入的图像;我玩过标准的动画结构,但似乎无法工作。

(图片代码:)

@Override
    public void draw(Canvas c, Layer layer) {
        if ( layer == Layer.BACKGROUND ) {              

            Animation a = new AlphaAnimation(1.00f, 0.00f);
            a.setDuration(4000);

            instructions.startAnimation(a);

            location.left = (view.getWidth() - instructions.getMinimumWidth() ) /2;
            location.right = location.left + instructions.getMinimumWidth();
            location.top = view.getHeight() / 2;
            location.bottom = location.top + instructions.getMinimumHeight();
            instructions.setBounds(location);
            instructions.draw(c);
        }
        //explosions.draw(c, layer);
    }
};

...“对于BitmapDrawable类型,startAnimation是未定义的,”它说。

2 个答案:

答案 0 :(得分:0)

startAnimationView的一种方法,因此如果您在ImageView实例imageView中有位图,则应调用imageView.startAnimation(a);。< / p>

答案 1 :(得分:0)

不要在代码中执行此操作,而应考虑使用XML:http://developer.android.com/guide/topics/resources/animation-resource.html#View