Android Question layout simple question

giggetto71

Active Member
Licensed User
Longtime User
Hi guys,
I really apologize for the trivial question but clearly there must be something fundamental I am missing in the layout design.
I have attached a sample program. The layout has one panel and the panel has 2 labels.


I would like to place label1 for half the width of the panel and label1 same size and left position equal to to the label1. basically each label should take half the size of the screen (the panel has both hor and ver anchors so it actually gets resized to the activity screen).
I have tried many combinations but I did not find anything that works. for example if I set both labels with "<->" anchor, I get the below effect. Is there a smart way to do that?
actually my real goal is to do the same with two customlistviews because I would like to have them covering each half of the screen..(the tests with the CLV are showing the same results..).
any help is really appreciated..
thanks in advance.



 

Attachments

  • Test1.zip
    9 KB · Views: 180

Sagenut

Expert
Licensed User
Longtime User
Set Label1 Top and Left anchors.
Set label 2 top and right anchors.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
You can also use the following designer script:
B4X:
Label1.SetLeftAndRight(0, 50%x)
Label2.SetLeftAndRight(51%x, 100%x)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You can also use the following designer script:
B4X:
Label1.SetLeftAndRight(0, 50%x)
Label2.SetLeftAndRight(51%x, 100%x)


This line is not correct as on some devices may leave a gap between the labels
Label2.SetLeftAndRight(51%x, 100%x)
it should be
Label2.SetLeftAndRight(50%x + 1dip, 100%x)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
To "fill" the horizontal space (or the vertical one) "correctly", only one view should have both sides anchored. I mean, in your case, label1 OR label2.
This way, however, you would not get the desired.

This line is not correct as on some devices may leave a gap between the labels
Label2.SetLeftAndRight(51%x, 100%x)
it should be
Label2.SetLeftAndRight(50%x + 1dip, 100%x)
Both solutions are not perfect, because of the same reason @Cableguy wrotes (in his solution there will be a "gap" of 1dip).

Keeping label1 anchored to the Left (it is anchored so by default), set its Left to 0dip, of course. Then:
B4X:
label1.Width = 50%X
label2.SetLeftAndRight(label1.Right, 100%x)
 
Last edited:
Upvote 1

vecino

Well-Known Member
Licensed User
Longtime User
To "fill" the horizontal space (or the vertical one) "correctly", only one view should have both sides anchored. I mean, in your case, label1 OR label2.
This way, however, you would not get the desired.
Where do they explain these things? books? experience?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Where do they explain these things? books? experience?
@klaus has a whole booklet series on b4x where he covers almost every aspect of working with b4x tools.
And then comes common sense and logic... after reading the appropriate chapters of the booklets.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Where do they explain these things? books? experience?
Relating to that answer of mine:
I read the first part in a few posts (for a long time, years, I read almost all the posts, almost like Erel does).
The second part is just a reasoning.

Books / manuals.
I think they can be useful for a beginner or to be consulted in case of need, but only having searched the Forum before, because it is easier and you can find a number of cases that can be exceptions.
I think it's a bit like being a lawyer: I don't think he studies a "criminal (or civil) code book" from the beginning, but he consults it when needed. The site, the forum, is a bit like consulting an archive of concluded lawsuits.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…