Android Question TabHost and Canvas for each Panel

PenguinHero

Member
Licensed User
Longtime User
Hi all,

I may have overlooked something obvious, but I've run into a problem with using a TabHost.

I want to add a canvas to each panel that is linked to the TabHost, but when I initialise the canvas naming one of the linked panels I get a Java exception at runtime.

I tried to create a new panel that would sit over the top of the same area as the linked panels, but couldn't work out how to provide the AddView with the correct coordinates and width/height. I get a run time error if I try and use a linked panel's top/left/width/height properties.
I have done it successfully using the TabHost properties, but of course this includes the tab area of the view, that I don't want to have the canvas write over.

So, how can I either use one of the existing linked panels (the preferred option), or determine the "working" area of the TabHost (without the tab area) so I can use another panel the correct size?


Thanks.
 

PenguinHero

Member
Licensed User
Longtime User
Thanks Erel, but I'm confused by that answer.

Firstly I'm creating the Tabhost and linked panels entirely in code, and the TabHost doesn't take up the whole screen.

E.g. Sample of my code:
B4X:
DrawingTabHost.Initialize("DrawingTab")
Activity.AddView(DrawingTabHost,0,0,75%x,85%y)
drawingpanel1.Initialize("DPanel1")
drawingpanel2.Initialize("DPanel2")

DrawingTabHost.AddTabWithIcon2 ("Farm", bmp1, bmp2, drawingpanel1)
DrawingTabHost.AddTabWithIcon2 ("Ocean", bmp3, bmp4, drawingpanel2)

And even if I used the designer like you suggest, I don't understand how I could use a canvas method like DrawLine on the panel without having already done something like:
B4X:
cvsDraw.Initialize (drawingpanel1)

If I do that canvas initialize then I get a runtime Java error.
 
Upvote 0

PenguinHero

Member
Licensed User
Longtime User
Thanks Erel, that works fine.

My only surprise is that I have to use the Designer for this, and that I can't achieve the same result using only code. I would have thought that since the TabHost must "know" what position/size its panels are, to use them, that this would would be available to the rest of the environment.
E.g. in my example code above I would have thought that I would be able to use drawingpanel1.height without getting a runtime error.
 
Upvote 0
Top