Get sizes after setLayoutParams in Android

In Android, after calling View.setLayoutParams , how can you find out the size (width and height) and position (x and y) of the view?

If I request these properties immediately after setLayoutParams , they return invalid values.

According to the documentation, View.onSizeChanged is called after the view is resized. Does this mean that I should subclass the widget whose dimensions I want to request, override onSizeChanged and report my change activity?

+4
source share
1 answer

I haven’t tried it myself, but until you add the view as a child and call invalidate () after you set layoutParams, I think you can determine the width and height.

0
source

Source: https://habr.com/ru/post/1332739/


All Articles