Android Question Adjusting the display

Tomek92

Member
Licensed User
Hi,

Could someone show me on my example layout how to use anchors and how to write a script in the designer to make the layout fit any display size?

I watched the Erel's guide about anchors, but still having a lot of problems, I guess I don't understand something yet.

I am slowly giving up because I have only problems... the views go beyond the screen, or the views overlap, or the views are unevenly distributed on the screen, or the views are too small or too large, or were even invisible.

When I used percentages (e.g. 10% x, 12% y) then the views on the other display were stretched or compressed, nothing had the original shape.

I can't control it... I need to see this with an example where there are more views.

Will you help please?
 

Attachments

  • main.bal
    12.8 KB · Views: 90
Solution
I am slowly giving up because I have only problems...

Don't give up! The Layout Designer has grown to be quite a complex piece of software. This means that it will take some time to learn how to use it fully. I don't use it very often and so I am not an expert - I have learned several new things while making this demo. You have got the basic ideas but are making some mistakes when using anchors.

Load the attached demo on your device and try it in both portrait and landscape mode. You will see in particular how the buttons resize and reposition themselves to adapt to the new screen width, and the bottom panel always extends to the bottom of the screen. Look at the script in the Designer; I have put some comments there.

Note...

William Lancee

Well-Known Member
Licensed User
Longtime User
% are bad news, and I can only talk about my experience with the Designer (I haven't used my own scripts).

There are two Anchor property items in Designer.
When you choose one, the lines underneath these properties change and describe exactly what you have chosen.
(left, top, distance from left edge, etc.)

You'll note that double arrow anchors make the width/height vary with screen size.

Anchors simplify many things but do not guarantee that your App will look good on all size screens.
Font size is another matter altogether.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I am slowly giving up because I have only problems...

Don't give up! The Layout Designer has grown to be quite a complex piece of software. This means that it will take some time to learn how to use it fully. I don't use it very often and so I am not an expert - I have learned several new things while making this demo. You have got the basic ideas but are making some mistakes when using anchors.

Load the attached demo on your device and try it in both portrait and landscape mode. You will see in particular how the buttons resize and reposition themselves to adapt to the new screen width, and the bottom panel always extends to the bottom of the screen. Look at the script in the Designer; I have put some comments there.

Note also that it is better to post a simple but complete app package rather than just a *.bal file. I did not do much with your sample file because I did not have the png files that it needed and I was too lazy to clean it up.

If you need more help post again, but post a complete project zip and explain exactly where you are having a problem. It was not always obvious to me what layout effects you were trying to achieve.
 

Attachments

  • Designer Demo.zip
    9.7 KB · Views: 111
Upvote 0
Solution

Tomek92

Member
Licensed User
William Lancee
Thanks for reply. Before that, I did the whole project in % and was very surprised when I installed the application on another device. Now I know that % is better to use e.g. to fill an area, or to align e.g. buttons, or to specify the distance between the views etc.
I started using anchors more.

Brian Dean
Thanks for the sample project, I'm beginning to understand that it's not always good to insert horizontal and vertical snap anchors for all views because the layout was broked with other screen sizes. I did it randomly because I didn't understand it.

I noticed you deleted the AutoScaleAll command from the designer script. I deleted it too, and it's better.

I've tweaked anchors my layout a bit and it looks better. It pleases when it starts to work :)

Thanks also for the code in the designer script because my next question would be "how to center the buttons". I guess you foresaw this question :D

I completely forgot that if I share a * .bal file, it won't be there * .png files, sorry for that.

I still have a question.
If I design a layout on the 320x480 scale = 1 variant, and I test on a 1080x2130 scale = 2.75 device, then for it to look good on the device, I would have to cross some view beyond the area in the designer or overlap views, because e.g. the view is too small on the tested device.
Is this a good approach? Do I have to do otherwise?
 
Last edited:
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I noticed you deleted the AutoScaleAll command from the designer script.
I do not usually delete AutoScale. AutoScale tries to improve larger layouts so was not applicable to my demo, but that was no reason to remove it either. You should give it a chance to work, although removing it will not do any harm.

I would have to cross some view beyond the area in the designer or overlap views.
That does not sound good, but I have seen some very congested layouts before. My advice would be - "If it works then don't worry about it.".

Let me remind you that I am not an expert on the Layout Designer - I responded to your first post because I did not want you to lose heart and give up. I have not used the Layout Designer in any published app, and even in my personal apps I often use coded layouts mixed in with Designer. Just keep going and I will soon be asking you for help.
 
Upvote 0

Tomek92

Member
Licensed User
I will test when it is best to use AutoScaleAll, or maybe scaling individual views, e.g. text in views.

I responded to your first post because I did not want you to lose heart and give up.

The more I appreciate your help for me. Sometimes it doesn't take much to show the right way.

Thank you so much for your time to help me. The more that you had to learn a several new things yourself, as you wrote earlier.

I asked the same question beforein other thread, but it still didn't work out as I wanted because I was still putting the anchors wrong. But now I'm beginning to understand.
 
Upvote 0
Top