Android Question Anchors

LucaMs

Expert
Licensed User
Longtime 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

(test on a tablet 1280x800 and a phone 800x480)



Designer:
 

Attachments

  • lm anchors test2.zip
    7.4 KB · Views: 290

LucaMs

Expert
Licensed User
Longtime User
Without anchors (and AutoScaleAll) but using percentages:


(I have only to scale the TextSizes)

B4X:
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.
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime 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?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime 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?


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

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

 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
In this case the scaling make sense. But on your previous examples not.


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.
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…