user1748526
user1748526

Reputation: 464

View's setX(), setY() and layout()

What actually a contract between that methods? I thought, layout() calls setX(), but somehow, layout() stops working after calling setX().

view.layout(256, 256, 512, 512);
view.setX(0);
view.layout(256, 256, 512, 512);

but view stays on {0, 256}. Why so?

Upvotes: 1

Views: 4516

Answers (2)

Asthme
Asthme

Reputation: 5353

In my Understainding child.layout(Int,int ,int ,int) used for identify how much bigger the child is.after drawing layout.u are settingX position to stay there..so it staying the x position with that size.

Upvotes: 1

Shankar
Shankar

Reputation: 528

 view.layout(256,256,512,512) 

means: Assign a size and position to a view and all of its descendants This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass(). Derived classes should not override this method. Derived classes with children should override onLayout. In that method, they should call layout on each of their children. Parameters l Left position, relative to parent t Top position, relative to parent r Right position, relative to parent b Bottom position, relative to parent

while view.getX()

The visual x position of this view, in pixels. This is equivalent to the translationX property plus the current left property. Returns The visual x position of this view, in pixels.

Hope this make sense...

Upvotes: 2

Related Questions