Android Question Problem with different screens

jeronimovilar

Active Member
Licensed User
Longtime User
B4X:
Sub GetRealSize As LayoutValues
    Dim lv As LayoutValues
    If p.SdkVersion >= 17 Then
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        Dim display As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window")).RunMethod("getDefaultDisplay", Null)
        Dim point As JavaObject
        point.InitializeNewInstance("android.graphics.Point", Null)
        display.RunMethod("getRealSize", Array(point))
        lv.Width = point.GetField("x")
        lv.Height = point.GetField("y")
    Else
        lv.Width = 100%x
        lv.Height = 100%y
    End If
    lv.Scale = 100dip / 100
    Log("GETREALSIZE: "& lv.Scale)
    Return lv
End Sub

Sub Activity_WindowFocusChanged(HasFocus As Boolean)
    If HasFocus Then
        Try
            Dim jo As JavaObject = Activity
            Sleep(300)
            jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
        Catch
            'Log(LastException) 'This can cause another error
        End Try 'ignore
    End If
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    LogColor("*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*x*x*x*x", Colors.green)
    
    Dim LY As LayoutValues
    LY = GetDeviceLayoutValues  '   
    Activity_WindowFocusChanged(True)
    Dim lv As LayoutValues = GetRealSize
    Log(lv & " - SDK: " & p.SdkVersion)
    Dim jo As JavaObject = Activity
    jo.RunMethod("setBottom", Array(lv.Height))
    jo.RunMethod("setRight", Array(lv.Width))
    Activity.Height = lv.Height
    Activity.Width = lv.Width
    
    Activity.LoadLayout("test")
    Log(Panel1.Width & "x" & Panel1.Height)
    Button1.Initialize("Button1")
    Panel1.AddView(Button1,Panel1.Left*1.2, Panel1.Top*1.2,Panel1.Width*0.80, Panel1.Height*0.80)
End Sub
My app works fine for screens for (SDK >= 19):
tablet = 976 x 600 (160), scale 1.0
smart = 1193 x 720 (320), scale 2.0
....but when the screen is 2280 x 1080, scale = 2.68 (428 dpi) is not ok
What do i need to change?
 

jeronimovilar

Active Member
Licensed User
Longtime User
OK....i´ll try explan:
i have a scrowview with 900 x 600 made im designer with variant 976x600 (1.0).

When i test in smart or tablet with scale 2.0 no problem because my scrowview will be 1800 x 1200, but if test in a smart with 2,68 scale (2280 x 1080) will be wrong because my scrowview = 2412 x 1608 and my screen is 1080 height.
is it clean?

sorry my english
 
Last edited:
Upvote 0
Top