在画布之上的Android地方的ImageView [英] Android place ImageView on top of Canvas
本文介绍了在画布之上的Android地方的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能显示在pviously创建的视图画布$ P $之上的编程方式创建的ImageView?我试着用bringToFront(),但没有成功。
how can I display a programmatically created ImageView on top of a previously created View Canvas? I tried using bringToFront(), but without success.
code:
RelativeLayout root = findViewById(R.id.layout);
ImageView img = new ImageView(GameGuessActivity.context);
img.setImageResource(R.drawable.image);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width, height);
params.leftMargin = x;
params.topMargin = y;
root.addView(img, params);
img.bringToFront();
正在显示的图像,但在画布上,这是我不希望的下方。
The Image is being displayed, but underneath the canvas, which I don't want.
推荐答案
您必须重新绘制在画布上的ImageView的:
You have to redraw your imageview on canvas:
pcanvas = new Canvas();
pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap
pcanvas.drawBitmap(bitmap, 0, 0, null);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
image.draw(pcanvas);
img.bringToFront();
img.invalidate();
img.draw(pcanvas);
这篇关于在画布之上的Android地方的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文