android - addOnLayoutChangeListener vs addOnGlobalLayoutListener vs post(Runnable r) -


problem: suppose have simple case: have view , have show data on view. use static method showdata(view view) this. want know exact moment when view layout measured , can access getwidth() getheight() , sure final width , height of view.

what know: (not sure 100% right):

i know 3 different approaches this

  • view.addonlayoutchangelistener - know when layout changed, can height , width
  • view.getviewtreeobserver().addongloballayoutlistener - case same, information later. because layoutchange bubbles children root, , globallayout root children (right?).
  • view.post(runnable r) - working, not know why runnable posted ui thread executes after view measured.

question: best approach know view measured? , why?

what best approach know view measured?

the best approach? ongloballayoutlistener view.getmeasuredheight() or view.getmeasuredwidth()

and why?

because mom knows better know yourself, better consult viewgroup state automatically speaks volumes children.

view.post() enqueues process on ui queue. ui queue ={1,2}, later after call line = {1,2,runnable}. run after 1,2


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -