TabHost problem with Icons

kaputo

Member
Licensed User
Longtime User
Hi, I have a tabhost created without icons. I have a view on a tab which has it's bottom position set as 100%y and all OK. If I do the same thing but this time using addTabWithIcon, then my view which is set at 100%y disappears from sight (or at least approx 15% of it). Any idea what might be the prob? Thanks
 

warwound

Expert
Licensed User
Longtime User
You're adding a Panel or some other View to a TabHost and when you add that Panel or View to a TabHost which has an Icon in it's Tab then the Panel or View height is incorrect...??

Try setting the Panel Height property to -1.

-1 is an Android shorthand that means stretch to fill available space.
It doesn't work the same as setting Height to 100%y so might work better for you.

Martin.
 
Upvote 0

kaputo

Member
Licensed User
Longtime User
Hi, the view which disappears from the bottom is not the full height of the tab. It has in the designer script SetTopAndBottom(80%y,100%y) which is fine when no icon in the tab heading, but when I have the icon I seem to lose screen estate - thanks for reply
 
Upvote 0

kaputo

Member
Licensed User
Longtime User
Hi, the view which disappears from the bottom is not the full height of the tab. It has in the designer script SetTopAndBottom(80%y,100%y) which is fine when no icon in the tab heading, but when I have the icon I seem to lose screen estate - thanks for reply

Hi, here is a 2-line example which shows the problem I have. Please see the difference between line 21 commented out and line 22 commented out - thanks
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
This is strange...

Run the attached version of your project.

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim TabHost1 As TabHost
   Dim AdPanel As Panel
   Dim MainPanel As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main")
    Dim bmp1, bmp2 As Bitmap
    bmp1 = LoadBitmap(File.DirAssets, "search.png")
    bmp2 = LoadBitmap(File.DirAssets, "search_light.png")
    
    TabHost1.AddTabWithIcon ("Search", bmp1, bmp2, "banner") 'load the layout file of each page
    TabHost1.AddTab("Search", "banner")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Select the tab with an icon and look at the corners of each Panel.
Now select the tab with no icon and look at the corners of each Panel.

The tab with no icon displays the rounded corners of each Panel - the MainPanel is correctly sized to fill the tab area and the AdPanel correctly sized to fill the tab area width.

BUT the tabarea in the tab with an icon shows that the Panels are overflowing the tab area - the tab area of the tab with an icon is not the same size as the tab area of the tab with no icon.

Maybe Erel can take a look and comment?

Martin.
 

Attachments

  • tab_area_size.zip
    10.2 KB · Views: 257
Upvote 0

kaputo

Member
Licensed User
Longtime User
Hi, thanks for taking a look at this and also noticing the problem (thought I was losing it!)

Erel, any chance you could have a look? Many thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is a bug. It will be fixed in the next update.

You can use this workaround:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main")
    Dim bmp1, bmp2 As Bitmap
    bmp1 = LoadBitmap(File.DirAssets, "search.png")
    bmp2 = LoadBitmap(File.DirAssets, "search_light.png")
    AddTabWithIcon(TabHost1, "Search", bmp1, bmp2, "banner")
    TabHost1.AddTab("Search", "banner")
End Sub

Sub AddTabWithIcon(th As TabHost, Title As String, bmp1 As Bitmap, bmp2 As Bitmap, LayoutFile As String) As Panel
    Dim p As Panel
    p.Initialize("")
   Activity.AddView(p, 100%x, 0, th.Width - 20dip, th.Height - 84dip)
    p.LoadLayout(LayoutFile)
   p.RemoveView
    th.AddTabWithIcon2(Title, bmp1, bmp2, p)
End Sub
 
Upvote 0

kaputo

Member
Licensed User
Longtime User
Hi, I still seem to have 2 problems. The first is that the label at the bottom of the layout has 4 text lines, but only 2 are visible. The second is that if I add another tab using your method, then I receive a null exception error when loading the second tab. Please have a look at the example - many thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should use File - Export as zip when uploading files.

The label is just too short. You should set it with the designer to a proper size and then change the script to:
B4X:
Label1.Bottom = 100%y 'instead of the SetTopAndBottom

There was an error in the code I posted. It should reference th instead of TabHost1. I've updated it.
 
Upvote 0

kaputo

Member
Licensed User
Longtime User
Hi, point taken about .bottom, thanks - however still receive null error. Please see uploaded project, many thanks
 
Upvote 0

kaputo

Member
Licensed User
Longtime User
The database is missing from the zip file (you should add files with the Files tab). However I commented the database code and the TabHost looks fine. How do you reproduce the error?

Hi, I uploaded the wrong project, sorry! Please look at the simple example below. In this I receive the null errors, and also all tabs are not shown. Thanks
 

Attachments

  • test3.zip
    12.2 KB · Views: 198
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Now I see it :)

The correct code should be:
B4X:
Sub AddTabWithIcon(th As TabHost, Title As String, bmp1 As Bitmap, bmp2 As Bitmap, LayoutFile As String) As Panel
    Dim p As Panel
    p.Initialize("")
   Activity.AddView(p, 100%x, 0, th.Width - 20dip, th.Height - 84dip)
    p.LoadLayout(LayoutFile)
   p.RemoveView
    th.AddTabWithIcon2(Title, bmp1, bmp2, p)
End Sub
 
Upvote 0

kaputo

Member
Licensed User
Longtime User
Now I see it :)

The correct code should be:
B4X:
Sub AddTabWithIcon(th As TabHost, Title As String, bmp1 As Bitmap, bmp2 As Bitmap, LayoutFile As String) As Panel
    Dim p As Panel
    p.Initialize("")
   Activity.AddView(p, 100%x, 0, th.Width - 20dip, th.Height - 84dip)
    p.LoadLayout(LayoutFile)
   p.RemoveView
    th.AddTabWithIcon2(Title, bmp1, bmp2, p)
End Sub

Perfect, many thanks for sticking with it
 
Upvote 0

MDEnt

Member
Licensed User
Longtime User
Hi - I was wondering if this bug was fixed in 1.92? I just stumbled across this post with a search as I am also experiencing a panel (text) strangely disappearing off the edge of a tabhost view.
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
The TabHostExtras Library may help with this too. There was some recent additions I requested because I was having issues...not sure if it was the same issues since mine were all image tabs, but there are a few more methods now that helped me with panel sizes. Tabs, Listviews, and Keyboards/IME have been my biggest let downs in Android so far. The library helped me with my panels, but I had to design my tab images with text in the image since the images overlap the region text is in. Android could have designed things a little better by now. There are still some suggestions in the TabHostExtras thread that B4A/Erel may need to implement or add to help get around some of Android's shortcomings too since it is difficult to do after the tabview is created.
 
Upvote 0
Top