Código para diferentes telas/smart

jeronimovilar

Active Member
Licensed User
Longtime User
Funciona para
tablet = 976 x 600 (160), scale 1.0
smart = 1193 x 720 (320), scale 2.0

Mas não funciona para 2280 x 1080, scale = 2.68 (428 dpi)
O que preciso mudar?


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
[QUOTE
 
Top