Android Question Screen width & height ?

Discussion in 'Android Questions' started by jinyistudio, Jan 23, 2015.

  1. jinyistudio

    jinyistudio Active Member Licensed User

    Hi

    I want to put a panel(fixed size) into the central of screen but i don't know get current screen width & height. Could you tell me how to do it ?
     
  2. mark35at

    mark35at Well-Known Member Licensed User

    Activity.Width or Activity.Height
     
  3. jinyistudio

    jinyistudio Active Member Licensed User

    My current code but the result of n1,n2 are zero

    Sub ShowPopupMenu(bShow As Boolean)
    Dim n1,n2 As Int

    n1 = (Activity.Width -Panel1.Width) Mod 2
    n2 = (Activity.Height-Panel1.Height) Mod 2


    Panel1.Left = n1
    Panel1.Top = n2

    Panel1.Visible = bShow
    End Sub
     
  4. jinyistudio

    jinyistudio Active Member Licensed User

     

    Attached Files:

  5. jinyistudio

    jinyistudio Active Member Licensed User

    Using following is OK, Thank's :(

    Private lv As LayoutValues

    lv = Activity.LoadLayout("bluelt_main")


    Sub ShowPopupMenu(bShow As Boolean)
    Dim n1,n2 As Int

    n1 = (lv.Width -Panel1.Width) / 2
    n2 = (lv.Height-Panel1.Height) / 2

    Panel1.Left = n1
    Panel1.Top = n2

    Panel1.Visible = bShow
    End Sub
     
  6. eurojam

    eurojam Well-Known Member Licensed User

    you have to assign your panel to the activity or any parent view before you can calculate any values with it. that the reason for the error you got. While loading the layout, the panel is assigned and you will get your values...
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Use designer script and set its HorizontalCenter to 50%x and VerticalCenter to 50%y.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice