Android Question Label cropped

Derek Jee

Active Member
Licensed User
Longtime User
Hi there

I have two labels, one left justified and the other right justified.. this is the code I am using

Label1.TextColor = Colors.Red
Label1.Gravity = Gravity.LEFT
Label1.Top = 0%x
Label1.Width = 100%x
Label1.Text = "Application Name"
Label1.TextSize = 1.5%x
DateTime.DateFormat = "dd/MM/yyyy"
Today = DateTime.Date(DateTime.Now)
Label2.Text= Today
Label2.TextColor = Colors.Green
Label2.Gravity = Gravity.RIGHT
Label2.Top = 0%x
Label2.Width = 100%x
Label2.TextSize = 1.5%x

I expect this to show the title pushed up to the left and the date pushed up to the right on the same line but it crops off the last digit of the year 29/09/201 instead of 29/09/2014 and when the orientation changes to portrait it crops of the last tow year digits.. I have a Samsung Galaxy Tab S..

Your help is much appreciated..

Derek.
 

James Chamblin

Active Member
Licensed User
Longtime User
Works fine for me. Samsung Galaxy S3. Where do you have the labels' left defined? If you have Label2.Left = 50%x and Label2.Width = 100%x, half the label will extend past the right edge of the screen. Try something like this.
B4X:
Label1.Left = 0
Label1.Width = 50%x
Label2.Left = 50%x
Label2.Width = 50%x

This will keep the labels from overlapping and also will keep the labels within the screen.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Label1.TextSize = 1.5%x
You should not set the TextSize proportional to the width of the screen !
With your code the size of the text is different depending on the screen orientation !?
You shouldn't either set values depending on the screen density, TextSize is density independant !
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Works fine for me. Samsung Galaxy S3. Where do you have the labels' left defined? If you have Label2.Left = 50%x and Label2.Width = 100%x, half the label will extend past the right edge of the screen. Try something like this.
B4X:
Label1.Left = 0
Label1.Width = 50%x
Label2.Left = 50%x
Label2.Width = 50%x

This will keep the labels from overlapping and also will keep the labels within the screen.


Thank you James..

It was the 'left' definition.. I had placed them on the designer on the left :) but I guess it wasn't at 0.. I added the Left = 0%x and it shows as expected.. Many thanks for your observations..

Derek.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Label1.TextSize = 1.5%x
You should not set the TextSize proportional to the width of the screen !
With your code the size of the text is different depending on the screen orientation !?
You shouldn't either set values depending on the screen density, TextSize is density independant !


Thank you Klaus

That's exactly what I was looking for. When the use turns the device I wanted it to show the text size a bit bigger as the use would only turn it because they couldn't read the text the size it was portrait.. Only a few controls will show like that but I do take on board your comments as I am only new and need all the help and advice I can get :)

Thank you,

Derek.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When the use turns the device I wanted it to show the text size a bit bigger ...
You must also make sure that the Label.Height is height enough to not crop the text verticaly.

Again, this Label1.TextSize = 1.5%x will not work properly on different screen densities.
On a screen with a size of 3.5' and a width of 320 pixels and density 1 you get a font size of 4.8.
On a screen with a size of 3.5' and a width of 480 pixels and density 1.5 you get a font size of 7.2, but the pysical sceen size remains the same !
Do you really want this ?
This will work Label1.TextSize = 1.5%x / GetDeviceLayoutValues.Scale.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Thank you Klaus

I am lucky with this project as the users have chosen one device and are not using any other. Once this project is complete though your suggestions will be very much what I need to incorporate into my apps..

Thank you :)

Derek.
 
Upvote 0
Top