Automatic Resize All device

Theera

Well-Known Member
Licensed User
Longtime User
Hi all,
I'm just test my widget for all device. I try to use the designer script. it's well done to solved my widget. I need to tell all,perhaps someone have the same problem. please see the 3 pictures. I think that understand.

P.S. It's my stupid way to solved it.

Best Regards
Theera
 
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I made my View Manager Class to try to do things like this. I haven't added code for Buttons yet, but Labels and Views are fully functional. It has a Document type Flow for adding new views in code (No Designer) that should work for flows like this. It will automatically size Views by font size and chars required too. Best when used in a Scroll View Panel and it will automatically extend the panel when needed too.
 
Upvote 0

dpalmond

Member
Licensed User
Longtime User
Resizing Views

I use the following functions to resize views and text. So far it seems to work pretty good on the divices I've tried it on.

Add this code to globals
B4X:
   Dim sY As Long : sY = 100%Y
   Dim sX As Long: sX = 100%X


I use this code to resize the view:
B4X:
Sub SetObjLayOut(obj As View, lt As Float, tp As Float, wd As Float, hg As Float, nsX As Long, nsY As Long)
   Dim xL, xT, xW, xH , scale As Float
   If sX > sY Then
      xL = (lt * nsX) / 480  
      xT = (tp * nsY) / 270  
      xW = (wd * nsX) / 480 
      xH = (hg * nsY) / 270   
   Else
      xL = (lt * nsX) / 320  
      xT = (tp * nsY) / 455  
      xW = (wd * nsX) / 320  
      xH = (hg * nsY) / 455   
   End If
   obj.SetLayout(xL * 1dip, xT * 1dip,xW * 1dip ,xH * 1dip) 
End Sub

then I use this code to resize text:
B4X:
Sub ScaleToSize(fSize As Float, bAdjDensity As Boolean, nsX As Long, nsY As Long) 
   Dim rate, slopeA, slopeB, scale, newsize, sd, d, ds As Float
   If nsX > nsY Then
      slopeA = Sqrt(Power(270,2) + Power(480,2))
   Else
      slopeA = Sqrt(Power(455,2) + Power(320,2))
   End If
   slopeB = (Sqrt(Power(100%Y,2) + Power(100%X,2)))
   
   scale = slopeB - slopeA
   rate = slopeA / fSize
   newsize = (scale / rate) + fSize

   d = 1
    sd = Density
   ds = d/sd
   If bAdjDensity Then
      Return newsize * ds
   Else
      Return newsize  
   End If
End Sub

Attached is a simple example of how I use them. With this code I don't have to create different variants for each device.
 

Attachments

  • Resizer.zip
    336.3 KB · Views: 281
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Automatically Convert Button in B4A

I made my View Manager Class to try to do things like this. I haven't added code for Buttons yet, but Labels and Views are fully functional. It has a Document type Flow for adding new views in code (No Designer) that should work for flows like this. It will automatically size Views by font size and chars required too. Best when used in a Scroll View Panel and it will automatically extend the panel when needed too.

Hi Roger Garstang
May I download your View Manager Manager Class and Example. I need new version of B4A has convertion automatically picture1 to picture2 with press the button as convert.

P.S. I'm not good at English

Best Regards
Theera
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I use the following functions to resize views and text. So far it seems to work pretty good on the divices I've tried it on.


Hi dpalmond,
Excuse me ,I tried to test your app. I need to know that "85" is come from? in your code.

Best Regards
Theera
 
Upvote 0
Top