Drawing to the canvas of a XML-constructed View

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Drawing to the canvas of a XML-constructed View

Postby darvari » Tue Jul 08, 2008 1:25 pm

In my Activity after

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.starter);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4

I'd like to manually draw to the canvas of that View or add a Button.

I don't know how to get the canvas of the view.

I did the following to get the view:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. View viewalias = (View) this.findViewById(R.layout.starter);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But I still need to get it's canvas - I think I'm missing something important.
I don't know the hierarchical relationships between a View and its canvas/bitmap/drawable or whatever.
I already experimented with code-completion - things like
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Canvas mycanvas = this.getWindow().getContainer().getContext() ...
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

Can somebody explain it to me or point me to a webpage that explains it?

to prevent a misunderstanding:
I know how to write a class that derives from View and then write drawing-instructions into the onDraw()-Method, but this time I want to draw from within the Activity onto the canvas of an XML-constructed view.
Is this possible?

Thanks in advance.
User avatar
darvari
Freshman
Freshman
 
Posts: 3
Joined: Tue Jul 08, 2008 1:11 pm

Top

Postby michael_g_hu » Wed Jul 09, 2008 3:23 am

what you need is just to rewrite the onDraw(Canvas canvas) of the view. it's simple
michael_g_hu
Developer
Developer
 
Posts: 35
Joined: Fri Mar 21, 2008 9:46 am

Postby darvari » Wed Jul 09, 2008 9:12 am

I think you got me wrong:
I'am not using a instantiated self-written View-class -
in other words I dont't have a View-derived class in my code.

instead the ui ist just plain xml-constructed in my 'main'-Activity and displayed via
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setContentView(R.layout.starter);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Now - from within my 'main'-Activity I want to add something to that ui, maybe a button, or just draw a text on the canvas using
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mCanvas.drawText("mytext",x,y,paint);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


the problem is: a mcanvas or similar is just available inside the onDraw(Canvas mCanvas)-method of a View-Objekt <--I know this.

My question is:
Can I acces the canvas of the xml-constructed View to draw on it - from within my 'main'-Activity?

Greetings

Darvari
User avatar
darvari
Freshman
Freshman
 
Posts: 3
Joined: Tue Jul 08, 2008 1:11 pm

Postby michael_g_hu » Thu Jul 10, 2008 3:41 am

then I think it's impossible to draw view in activity
michael_g_hu
Developer
Developer
 
Posts: 35
Joined: Fri Mar 21, 2008 9:46 am

Postby darvari » Fri Jul 11, 2008 9:16 am

michael_g_hu wrote:then I think it's impossible to draw view in activity


Thanks for answering.
Darvari
User avatar
darvari
Freshman
Freshman
 
Posts: 3
Joined: Tue Jul 08, 2008 1:11 pm

Postby Nemat » Sat Aug 30, 2008 12:49 pm

Hi darvari;

Have u solved the problem??Becoz I m also trying to Draw something in the class which extends Activity.
If its not possible then what can I do to draw after using XML.
I think I have to use a class which extends View.Then It will be added on the layout used in the class which extends activity.
I dont know Its right or not......
Anyone can suggest me?????
Nemat
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Thu Aug 21, 2008 3:16 pm
Location: Jaipur

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests