Width reduced in TableHost

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello
Why when I use "TableHost" an object with 100% of x in a layout exceeds the right edge. I am forced to program in the layout an object with 95% of x for full view when TableHost is used.
thank you
 

Attachments

  • Av1.png
    Av1.png
    38.6 KB · Views: 250
  • Av2.png
    Av2.png
    84.7 KB · Views: 249

Informatix

Expert
Licensed User
Longtime User
I'm surprised because I was used to set my views in TabHosts to 100%x minus a margin. I have some real examples where 100%x only is too wide. I don't understand why (I probably made something wrong somewhere) and since I replace these values now by -1, all is ok.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
The proof:

With that code, I get the first screenshot:
B4X:
         Dim lbl As Label
         lbl.Initialize("")
         Dim cd As ColorDrawable
         cd.Initialize(Colors.Blue, 10dip)
         lbl.Background = cd
         pnlAudio.AddView(lbl, 0, 0, 100%x, 30dip)

With the following code (I just replaced 100%x by -1), I get the second screenshot:
B4X:
         Dim lbl As Label
         lbl.Initialize("")
         Dim cd As ColorDrawable
         cd.Initialize(Colors.Blue, 10dip)
         lbl.Background = cd
         pnlAudio.AddView(lbl, 0, 0, -1, 30dip)

The pnlAudio width is automatically sized by the TabHost when I initialize it. And I don't change this width after that. This example is a very common TabHost use, I think.
 

Attachments

  • img1.jpg
    img1.jpg
    16.6 KB · Views: 221
  • img2.jpg
    img2.jpg
    15.6 KB · Views: 243
Upvote 0

Informatix

Expert
Licensed User
Longtime User
No one said that -1 will not work.

Ok, but why, in my example, 100%x does not work ? That should give exactly the same result as -1. I checked the widths (I used the "getWidth" method) and here are the results:
pnlAudio width (with both solutions) = 452
lbl width (100%x) = 480
lbl width (-1) = 452

It seems there's a bug with 100%x in that particular case.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
100%x always returns the Activity width. Only in the designer script, the percentage is related to the main parent (Activity when you call Activity.LoadLayout, Panel when you call Panel.LoadLayout or TabHost when you call TabHost.AddTab).

Do you realize you're working on a sunday ? You should go to the beach, enjoy the sun, repaint your shutters, hack the Pentagon servers, behead some elves with an axe, but ... working ? You're crazy :)
Anyway, thanks for the info. I wasn't aware of the difference.
 
Upvote 0
Top