开发者

What listener would tell me that when the drawing of a view has finished so i can get height of the view?

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开发者_如何学JAVA 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜