Android:SetImageResource和OnDraw

时间:2016-03-30 00:44:09

标签: android image imageview ondraw

我知道我可以在ImageView中设置setImageResource来设置图像,而onDraw可以在那里进行任何自定义绘制操作。您在onDraw函数中绘制的任何内容都将覆盖SetImageResource中的图像集。我的意思是如果我绘制透明的东西,它会使该部分的SetImageResource设置的图像也是透明的。

1 个答案:

答案 0 :(得分:0)

不,它不会。您可以通过创建扩展ImageView的视图来自行测试

public class TestView extends ImageView {

    public TestView(Context context) {
        super(context);
    }

    public TestView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //if you call super.onDraw first, then whatever you draw below will be on top of your image
        canvas.drawARGB(122, 122, 122, 122);
    }
}
相关问题