SurfaceView设置背景颜色遮挡问题
我在SurfaceView中想给画布设置背景颜色,使用了setBackgroundColor这个方法把背景设置为白色,结果我绘制在画布上的图案全部被遮挡,能有什么办法解决吗?
[解决办法]
你可以设置图片输出
public void setBackgroundResource (int resid)
Set the background to a given resource. The resource should refer to a Drawable object.
Related XML Attributes
android:background
Parametersresid The identifier of the resource.
取出图片资源
surfaceview.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.bg));
[解决办法]
楼主可以绘制一个全屏的填充矩形,颜色为白色,就相当于背景了。
- Java code
// 首先定义一个paint Paint paint = new Paint(); // 绘制矩形区域-实心矩形 // 设置颜色 paint.setColor(Color.BLUE); // 设置样式-填充 paint.setStyle(Style.FILL); // 绘制一个矩形 canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
[解决办法]
呵呵 白色的图片是bitmap吧,如果你的程序资源占用很多的话,注意bitmap的内存泄露啊