User drawing isn't showing on the canvas
I have an XML layout like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.somedomain.drawings.DrawingSurface
android:layou开发者_高级运维t_width="fill_parent"
android:layout_height="200dip"
android:id="@+id/drawingSurface"
android:background="@drawable/bg2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="OK"
android:onClick="onClick"
android:id="@+id/colorGreenBtn" />
</LinearLayout>
</RelativeLayout>
When I'm trying to draw on the DrawingSurface, the drawing isn't showing. But the background image of the canvas is showing. And when I save it, the drawing is showing on the output.
When I removed the background image of the DrawingSurface and try to draw to it, it is showing.
I want to show the drawing when the user draws on the canvas with the background image. Any ideas? Thanks a lot for any help! :)
Update: Here's my drawing code
@Override
public void run() {
Canvas canvas = null;
while (_run){
if(isDrawing == true){
try{
canvas = mSurfaceHolder.lockCanvas(null);
if(mBitmap == null){
mBitmap = Bitmap.createBitmap (1, 1, Bitmap.Config.ARGB_8888);
}
final Canvas c = new Canvas (mBitmap);
c.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(0x00000000);
commandManager.executeAll(c,previewDoneHandler);
previewPath.draw(c);
canvas.drawBitmap (mBitmap, 0, 0,null);
} finally {
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
Couple things to try:
1) put the ImageView before the drawSurface in XML, and put the bg into the ImageView.
I know the surfaceView is different than other view, but you could try out.
2) Maybe you could draw the bg onto the canvas first the drawing thread started. canvas.drawBitmap() could be the one you wanna use.
精彩评论