I am programmatically adding a view to the Layout and after i add that i need to get the height of new view when i ask for height of new view simply i get 0. Is there any way to know when a view has finished drawing and it can provide its height ?
To be more clear i am adding a AdVhirlLayout to the my root layout with myMainLayout.addView(adWhirlLayout, 0, adLayoutparams); the next line is adWhirlLayout.getHeight();
which retruns 0. I have added OnHierarchyChangeListenerto the adWhirlLayout and i am trying to get the height of the adWhirlLayout but still it returns 0. There must be another listener which will let me know if the drawing of adWhirlLayout has finished.
adWhirlLayout.setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
@Override
public void onChildViewRemoved(View parent, View child) {}
@Override
public void onChildViewAdded(View parent, View child) {
adWhirlLayout.getHeight();
}
});
You can add an
OnLayoutChangeListener.You can also override onSizeChanged in the view to respond when the view size is set on layout.