Android Question Designer scripts in the Visual Designer booklet

Tom_707

Member
Licensed User
I have a question about what's written in the Visual Designer booklet about designer scripts. In the example, it says that the right anchor for ScrollView1 is lost, so you need to use the SetLeftAndRight method. What I don't understand is why is the right anchor lost, and why can't you just use the Width method in the script, just like for ListView1? This is the screenshot of the relevant part in the Visual Designer booklet:


booklet.png
 

klaus

Expert
Licensed User
Longtime User
The problem in this example is the following:
The left view has the horizontal anchor set to LEFT with a given width,
The right view has the horizontal anchor set to RIGHT with a given width.
The space between the two views depends on the width of the parent view.
The wider the parent view the wider the space.

For your question: ... and why can't you just use the Width method in the script, just like for ListView1?
Because, when you set the width in the Designer Scripts it take as the reference the Left property and not the right anchor.
Test it and you will see the difference.
 
Upvote 0

Tom_707

Member
Licensed User
For your question: ... and why can't you just use the Width method in the script, just like for ListView1?
Because, when you set the width in the Designer Scripts it take as the reference the Left property and not the right anchor.
Test it and you will see the difference.


Thanks Klaus. I tried it and sure enough, the Width property didn't work as expected.

But I still don't know why. Surely if you use Width = 50%x then that should give you half the screen width, irrespective of whether its using the Left property or the right anchor as a reference. What am I missing here?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If you use Width = 50%x, it sets the width to half the screen width.
And where is it horizontally positioned ?
The left edge remains where it is.
Lets take an example:
You set, in the Designer, a width of 40%x, the anchor to RIGHT and the right edge aligned with the right edge of the screen.
This means that the Left position or edge is at 60%x and the right edge at 100%x.
Then when you set the width, in the Designer Script, to 50%x.
The Left position remains where it is at 60%x but the right edge moves to 60%x + 50%x = 110%x, therfore 10% out of the screen.
 
Upvote 0

Tom_707

Member
Licensed User
This is exactly what I am not understanding. Why does the left edge remain at 60%x while the right edge moves to 110%x. If you are anchoring to the RIGHT, then surely it is the RIGHT edge which should remain stationary, while the left edge should move (by 50%x from the right edge).

Why does the script only recognise left anchors, but ignore right anchors?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Why does the script only recognise left anchors, but ignore right anchors?
Check the first 20 lines or so of this link. They may help in revealing the reasons you were questioning.
 
Upvote 0

Tom_707

Member
Licensed User
Check the first 20 lines or so of this link. They may help in revealing the reasons you were questioning.


I've gone through that tutorial before, and understand how anchors work. After re-reading it, I got the following out of it:
Note that the anchors effect ends right before the designer script starts.


I obviously need to figure out the mechanics of how designer scripts work.

Thanks Mahares.
 
Upvote 0

Tom_707

Member
Licensed User
Only Erel can answer this question.


Oh, OK. So it's the way the Designer scripts have been programmed, and not something I'm misunderstanding.

Thanks Klaus.

So all values in Designer scripts need to be defined relative to the left side of the parent View. Is this correct?
 
Upvote 0
Top