Without resorting to the infamous onGlobalLayoutListener()
solution, and without having to implement a custom View, what lifecycle event in a Fragment can I put code into and be sure all of the Fragment's Views have been given a size?
As a corollary, I would also like this lifecycle event to be applicable to Fragments in a ViewPager.
I dont think there would be any Fragment lifecycle event to be sure all the Views have size.
What I would usually do is, to use OnLayoutChangeListener inside onActivityCreated(). Like this,
getView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
getView().removeOnLayoutChangeListener(this);
// Check the size of Views here.
}
});
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