dagav
dagav

Reputation: 47

Draw bitmap to canvas, being the main activity?

I want to draw a bitmap to the canvas, but don't know how to make the canvas the main screen.

Basically, I want to draw a bitmap to the main activity using a canvas. I know how to draw bitmaps to canvases but it doesn't show up anywhere that I can see (with only one activity). I want the bitmap to show up on the main activity. How do I do this?

Upvotes: 0

Views: 444

Answers (1)

saiful103a
saiful103a

Reputation: 1129

What you are trying to do is create your own CustomView. When you are putting a button or anything in your layout file that is actually a view. Android does allow you to create your own view to manually handle things on the screen. Games are usually implemented that way. They use customview by extending SurfaceView/GLSurfaceView.

As for the solution of your problem:

  • create a custom view by extending the View.
  • add all the constructor from superclass.
  • override onDraw method
  • onDraw method will pass you a canvas for you to draw
  • draw whatever you like(Bitmap, line ,....) using canvas

In your layout file include the customview you just created.

<my.packagename.MyCustomView android:width .... > </my.packagename.MyCustomView>

Hope this helps. Also you will find lots good resources on how you can create your own customview.

Upvotes: 0

Related Questions