iOS Code Snippet Resize all views to any screen size...

a simple way i resize all my views created in designer to all screen size is like this

B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)

'////// Start resize all views to fit all screensize //////

    'start rexize all views
    Dim ratiox As Float = Width/320 'iphone 4 3.5" = x320
    Dim ratioy As Float = Height/460 'iphone 4 3.5" = y480 - 20 !
  
    For Each v As View In Page1.RootPanel.GetAllViewsRecursive
        If Not(v.Tag = "drm") Then 'drm = dont resize me...
            v.Width = v.Width*ratiox
            v.Height = v.Height*ratioy
            v.Left = v.Left*ratiox
            v.Top = v.Top*ratioy
        End If
    Next

'////// End resize all views ///////

End Sub

i create the game/app in designer with variant 320x480 (iphone4) and with this code all devices screen size should work, if you are changing views location/size in code then use allways % of x/y !!

like: img1.height = 8%y
img1.width = 10%x

or game speed: dim speed as float = 0.8%y

regards, ilan

EDIT: very importent thing to do is to delete this line in the Designer Script "'AutoScaleAll"
if not it wont work correctly....
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
I tried this, had a nice looking code for my iphone 5 320x568
tried it on ipad , but couldnt get a result. maybe i am doing stg wrong
 

ilan

Expert
Licensed User
Longtime User
I tried this, had a nice looking code for my iphone 5 320x568
tried it on ipad , but couldnt get a result. maybe i am doing stg wrong

hi, what variant are u using in designer?

what size did u use in those two lines?

Dim ratiox AsFloat = Width/320'iphone 4 3.5" = x320
Dim ratioy AsFloat = Height/460'iphone 4 3.5" = y480 - 20 !

320 and 460??

could u put screenshots?

note that this method only zooms all views in and out, its not really the best method to use but you should not see any blank area with this method on your pages!
 

tufanv

Expert
Licensed User
Longtime User
Yes i changed those with 320 and 568-20 = 548 for variant created for iphone 5. I will check again . TY
 

ilan

Expert
Licensed User
Longtime User
Yes i changed those with 320 and 568-20 = 548 for variant created for iphone 5. I will check again . TY

very importent thing to do is to delete this line in the Designer Script "'AutoScaleAll"
if not it wont work correctly....
 
Top