Example of a simple canvas ?

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Example of a simple canvas ?

Postby Lex » Sun Dec 16, 2007 1:33 am

Hi, my question is probably really dumb but I don't see any example illustrating what I'm looking for.

I have an activity. I call setContentView(R.layout.main), where main.xml is the layout of my main activity.
I'd like to display a red rectangle (using a canvas ) in this main view. How can I do that ?
How to insert a View into another view ?

Posts: 30
Joined: Fri Nov 16, 2007 11:03 pm


Postby res » Fri Jan 18, 2008 12:40 am

If you have a View you can use "protected void onDraw(Canvas canvas)" method to paint on the screen.
Senior Developer
Senior Developer
Posts: 146
Joined: Tue Nov 20, 2007 8:14 pm
Location: United States

Postby plusminus » Fri Jan 18, 2008 1:10 am

Hello Lex,

For cascading Views ( View in View in View...) have a look at the SingleWeatherInfoView of the :src: Android Weather Forecast-Tutorial.
or any main.xml on this board :!: (in most cases everything is surrounded by a LinearLayout...).

Image | Android Development Community / Tutorials
User avatar
Site Admin
Site Admin
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany


Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests