Android Question Label resizing with code problem

chuck3e

Active Member
Licensed User
Longtime User
I've been over this logic a hundred times and I cannot find a problem. I have 5 buttons on top of black labels to make a black border effect around the buttons. Every one comes out as I want except for the last one. The last one's border looks ok for a fraction of a second then the label springs back to a smaller size. I've included a zip file of the code for inspection.

One bizarre thing is that this works fine on a 7" Rio tablet Android 4.0.4 but not on a 10.1 " Samsung Tab4 Android 4.4.2.
 

Attachments

  • Background Problem.zip
    57.6 KB · Views: 121

klaus

Expert
Licensed User
Longtime User
You must dim a ColorDrawable for each button!
If you add a routine like this:
B4X:
Sub SetRadiusBlack As ColorDrawable
    Dim cdw As ColorDrawable
    cdw.Initialize(ColorD, 90dip)
    Return cdw
End Sub
And replace everywhere:
xxx.Background = RadiusBlack
by
xxx.Background = SetRadiusBlack
it works OK.
You can of course change the routine above to make it more universal.

In your code you define the colors as Double, they must be Int.

For the TextSizeRatio you use If lv.Width > 1100 Then to define if the device is a 10'' tablet.
This leads to wrong results.
My 5'' Sony xperia Z1 has a width of 1980 pixels and is considered as a 10'' tablet.
You should use lv.ApproximateScreenSize which gives you directly the screen size !
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
You must dim a ColorDrawable for each button!......

Klaus, Thank you very much for the quick reply and for going above and beyond my question. I will implement these suggestions. I'm still learning how to address the multiple screen size issue as well as just learning the B4 code. You and Erel and the many other helpful people on this site are so appreciated. I am amazed at how you handle the seemingly hundreds of questions posted every day.
Chuck
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Klaus, Your suggestions on setRadiusBlack fixed my problem, thank you very much.
It looks like your suggestion on using ApproximateScreenSize will work great with both my 10" tablet and my 7" but I don't know how to tell when to divide by 10 or by 7 within my code. Is that information supposed to be part of the LayoutValues object? I did some searches on the forum but I didn't see any examples of how to do this.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Klaus, Your suggestions on setRadiusBlack fixed my problem, thank you very much.
It looks like your suggestion on using ApproximateScreenSize will work great with both my 10" tablet and my 7" but I don't know how to tell when to divide by 10 or by 7 within my code. Is that information supposed to be part of the LayoutValues object? I did some searches on the forum but I didn't see any examples of how to do this.

A function from the module "Scale".
B4X:
'Gets the approximate phyiscal screen size in inches
'Exemple:
'<code>DeviceSize = Scale.GetDevicePhysicalSize</code>
Public Sub GetDevicePhysicalSize As Float
    Dim lv As LayoutValues

    lv = GetDeviceLayoutValues
    Return Sqrt(Power(lv.Height / lv.Scale / 160, 2) + Power(lv.Width / lv.Scale / 160, 2))
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
ApproximateScreenSize is part of the LayoutValues object.
B4X:
Dim lv As LayoutValues

lv = GetDeviceLayoutValues
If lv.ApproximateScreenSize > 8 Then
    ' 10''
Else If lv.ApproximateScreenSize > 5.5 And lv.ApproximateScreenSize <=8 Then
    ' 7''
Else
    ' smartpohone
End If
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Klaus,
For information only:

Bottom line...thank you for your help, and LucaMs too. You guys are great!!!!

Using your and LucaMs's GetDevicePhysicalSize example I get the following results:

GetDevicePhysicalSize = 9.433980941772461 for my Samsung 10.1", 1280x800, scale 1, 160dpi, Android 4.4.2
GetDevicePhysicalSize = 7.823681831359863 for my Rio 9.7", 1024x720, scale 1, 160dpi, Android 4.0.4
GetDevicePhysicalSize = 7.624594688415527 for my Rio 7", 800x444, scale 0.75, 120dpi, Android 4.0.4

So, it appears the formula is not that accurate, however, when I divide lv.ApproximateScreenSize by GetDevicePhysicalSize I get very good aesthetic results, better than dividing by just 10 or 7. My button text now appears proportional across all three screen sizes. I noticed at BestBuy there is an 8" screen on the market too. When will the madness end? :eek:

I am also using my TextSizeRatio value for resizing my button widths across the three devices with good success. I don't know if this is recommended but it works. ie;

B4X:
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
TextSizeRatio = lv.Approximatescreensize / ScreenSize
EspBtn.TextSize = EspBtn.TextSize * TextSizeRatio
EspBtn.width = EspBtn.width * TextSizeRatio

Public Sub ScreenSize As Float
    Dim lv As LayoutValues
    lv = GetDeviceLayoutValues
    Return Sqrt(Power(lv.Height / lv.Scale / 160, 2) + Power(lv.Width / lv.Scale / 160, 2))
End Sub

Thanks again for the help.
Chuck
 
Upvote 0
Top