pavelkorolevxyz
pavelkorolevxyz

Reputation: 1500

How to update view position after view.layout() method?

I'm trying to set position to view at activity start.

I found out that the most of my problems was about getting layout coordinates in onCreate method, so I wrote it in onWindowFocusChanged, coordinates aren't 0s, so I now can set position of view with layout() method.

I did it, but view didn't update its position. By the way, in my log view has new position.

I think there is a method which should update view, give me a hint, please.

Thanks in advance.

Upvotes: 0

Views: 1826

Answers (1)

Bharat Sharma
Bharat Sharma

Reputation: 3966

you can get layout params by using getLayoutParams() and the change margin then again set layout param.

  1. RelativeLayout.LayoutParams param = View.getLayoutParams();

  2. set margins in your param according to your new position.

  3. View.setLayoutParams(param).

If it is not solving your problem then please respond me so that I can try something else

Upvotes: 2

Related Questions