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
Post a Comment