Android Question How can i tile image to tabhost background

Said

Member
Licensed User
Longtime User
Hi all,

First of all, i am old programmer but rookie android programmer. Please consider this situation.

I want to tile little background images to my activity backgrounds. I am using thedesolatedsoul's routine to tiling image from link below.

http://www.b4x.com/android/forum/threads/tiling-an-image-settiledbackground.39310/#content

It works perfect, thanks to him but i have problem. I created tabhost and attached 5 activity. I want to tile all backgrounds (5) different. I tried to set tiled backgrounds at start and right after adding tabhost1.add but it didnt worked and all tabs use same background.

Then i tried changing all tabs in code manually with tabhost1.currenttab and set background tiled image, but it didnt worked.

Then i tried to build array flag for all tabs and when user clicks one, immediately set background tile and set flag on to prevent redraw background for further clicks but it didnt worked again.

And i solved problem, when user clicks any tab, i am tiling (redrawing) image background everytime like code below;

Select Case TabHost1.CurrentTab
Case 0
BackgroundBMP = LoadBitmap(File.DirAssets, "10bgc.jpg")
SetTiledBackground(TabHost1, BackgroundBMP)

Case 1
BackgroundBMP = LoadBitmap(File.DirAssets, "red008.jpg")
SetTiledBackground(TabHost1, BackgroundBMP)

Case 2
BackgroundBMP = LoadBitmap(File.DirAssets, "bluesoft.gif")
SetTiledBackground(TabHost1, BackgroundBMP)

Case 3
BackgroundBMP = LoadBitmap(File.DirAssets, "graybrck.jpg")
SetTiledBackground(TabHost1, BackgroundBMP)

Case 4
BackgroundBMP = LoadBitmap(File.DirAssets, "12a.jpg")
SetTiledBackground(TabHost1, BackgroundBMP)
End Select

It works but everytime user clicks any tab, it redraws background and its not optimized code. It re-paints background again, again and again.

How can i tile backgrounds at start ? Any method ? Or i have to repaint activites everytime and wasting cpu ?

regards,

-said
 

Said

Member
Licensed User
Longtime User
Hi and thanks for advice Erel.

But now, i have two problems. Easy one first;

Panel is bit smaller than tabhost and some empty and (not painted) areas will be appears. But i have one idea to solve this. I'll add one more tiled background to main activity layout and try to camuflage empty areas. Probably it will look bit better.

The second problem is bigger rookie problem. Normally i was adding activities and selecting them at the bar below IDE menu and writing code there easily. But i cant see that code now. I have 5 layouts for tabhost (like new, stat, help etc) and i put some buttons and other views on this layouts.

When i tried to using tab host and build layouts for tab, and added them to the main module (activity create) via code, i cant see that activities on the 'activities bar' at top. Because of that, i cant add any code to that activites except 'script' on designer layout menu. But i see that layouts (.bal files) at the files section.

I know its little problem but i didnt figured is it IDE problem or general activity cycle/layout architecture problem? May be i understand something wrong. I tought activity layouts are like forms in vbasic but looks like it is not. If its general framework/layout rule, how can i add code for them ? Setting their names different and add all code in to main activity or what ? I read some articles like 'activity cycle' but i didnt any answer for my special questions. If i want to add code to layouts, i should not use tabhost ?

Regards,
 
Upvote 0

Said

Member
Licensed User
Longtime User
Better question should be like this i think;

"For example, i have some activity modules build before which include some events and other code. Can i assign this activities to tabhost view ?"

-regards
 
Last edited:
Upvote 0

Said

Member
Licensed User
Longtime User
I search, search and search again and figured that, i can't assign activity modules (with code) to the tabhost. At least i didnt any example :)

And i'll work with designer layouts and change all view names for this situation.

Now i put one tabhost and put 5 panels inside tabhost (for each tab). Set backgrounds once and it works fine. Thanks again for idea Erel.
 
Upvote 0
Top