PROBLEM: Suppose we have simple case: we have view and we have to show some data on this view. We use static method showData(View view) to do this. I want to know the exact moment when view layout is measured and I can access getWidth() getHeight() and be sure that this is final width and height of my view.
WHAT I KNOW: (not sure I am 100% right):
I know 3 different approaches to do this
QUESTION: What is the best approach to know that view is measured? and why?
What is the best approach to know that view is measured?
The best Approach? OnGlobalLayoutListener
with View.getMeasuredHeight()
or View.getMeasuredWidth()
and why?
Because your mom knows you better than you know yourself, so its better to consult the ViewGroup
about its state which automatically speaks volumes about the children.
View.post()
enqueues process on the ui queue. Ui queue ={1,2}, later after you call that line = {1,2,runnable}. so definitely it will run after 1,2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With