I have this activity where in I need to do some layout at runtime (in this particular instance I need to set the indicator bounds (ExpandableListView.setIndicatorBound
) so that the group indicator aligns to the right side of the view instead of the default left.
I've got this code in my Activity:onCreate
:
int viewWidth = mListView.getWidth();
int groupIndicatorWidth = getResources().getDrawable(R.drawable.up).getMinimumWidth();
mListView.setIndicatorBounds(viewWidth - groupIndicatorWidth, viewWidth);
app.fetchItems(this);
Quite understandably, viewWidth
turns out to be 0
at runtime.
My question is what method should I implement/overload when the view's children would have been laid out and their dimensions valid? Basically on Windows we would generally put such code in OnSize/OnResize.
I found Activity:onPostCreate
and Activity:onPostResume
, but I also found this in the docs - "Applications will generally not implement this method; it is intended for system classes to do final initialization after application code has run."
Edit
Found this thread which has several workarounds listed: Android: Need to use onSizeChanged for View.getWidth/Height() in class extending Activity