Android Question Anchors

Discussion in 'Android Questions' started by LucaMs, Jul 12, 2015.

  1. LucaMs

    LucaMs Expert Licensed User

    To get a right scaled panel inside and activity, Erel answered:

    "The second step is to set the vertical and horizontal anchors to BOTH."

    It is right and it works well.

    So I thought if I set both :) anchors to BOTH on all views children of that panel, I get a well scaled layout.

    The result is not exactly so perfect, as you can see :D

    (test on a tablet 1280x800 and a phone 800x480)
    upload_2015-7-12_15-1-7.png


    Designer:
    upload_2015-7-12_15-1-53.png
     

    Attached Files:

  2. LucaMs

    LucaMs Expert Licensed User

    Without anchors (and AutoScaleAll) but using percentages:
    upload_2015-7-12_15-57-11.png

    (I have only to scale the TextSizes)

    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("layMain")
       
        pnlSquare.Width = 
    41.6667%x
        pnlSquare.Height = 
    62.5%y
        pnlSquare.Left = (
    100%x - pnlSquare.Width) / 2
        pnlSquare.Top = (
    100%y - pnlSquare.Height) / 2
       
        Label1.Width = pnlSquare.Width * 
    0.5
        Label1.Height = pnlSquare.Height * 
    0.25
        Label1.Left = pnlSquare.Width * 
    0.25
        Label1.Top = pnlSquare.Height * 
    0.05
       
        EditText1.Width = pnlSquare.Width * 
    0.4
        EditText1.Height = pnlSquare.Height * 
    0.25
        EditText1.Left = pnlSquare.Width * 
    0.05
        EditText1.Top = pnlSquare.Height * 
    0.4
       
        EditText2.Width = pnlSquare.Width * 
    0.4
        EditText2.Height = pnlSquare.Height * 
    0.25
        EditText2.Left = pnlSquare.Width * 
    0.55
        EditText2.Top = pnlSquare.Height * 
    0.4
       
        Button1.Width = pnlSquare.Width * 
    0.5
        Button1.Height = pnlSquare.Height * 
    0.25
        Button1.Left = pnlSquare.Width * 
    0.25
        Button1.Top = pnlSquare.Height * 
    0.7
       
    End Sub
    Then I wish a "code generator" in the Designer.
     
  3. MaFu

    MaFu Well-Known Member Licensed User

    Still i don't understand your intention. Because your tablet screen is much larger as your phone screen, the dialog will also be much larger in this case. For what reason? What's all that in aid of?
     
  4. LucaMs

    LucaMs Expert Licensed User


    The dialog is just an example !!!

    (damn; maybe my English is worse than I imagined)

    I don't know why I'm so mad to want a layout well scaled on many devices :confused::)

    Screenshots from my phone (left) and my tablet (right).

    upload_2015-7-13_0-25-20.png
     
  5. MaFu

    MaFu Well-Known Member Licensed User

    In this case the scaling make sense. But on your previous examples not. :D
     
  6. LucaMs

    LucaMs Expert Licensed User


    Why not? What is the difference between a dialog and that panel with "Fruit Splash"?

    Well, it does not matter. I just want to say that you can use anchors, AutoScaleAll, scripts... but you can obtain that result using percentages!
    But, as you know, if I had to write the code like the one I posted in #2, I have to do many calculations, which the Designer could do very simply.
     
  7. MaFu

    MaFu Well-Known Member Licensed User

    Because a full screen game has a fixed content and therefore the scaling make sense.
    For "normal" apps the larger screen should be used to show more data, not bigger views.
     
    DonManfred and Erel like this.
Loading...