Capture Layout resize before API 11

后端 未结 2 1238
情歌与酒
情歌与酒 2021-01-06 09:49

I am dynamically creating a board, made of views that are dynamically set in a relative layout. In my onCreate i call the constructor of my Board class that creates everythi

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-06 09:58

    The most elegant solution is to extend RelativeLayout class, then you can just override onSizeChanged:

    protected void onSizeChanged (int w, int h, int oldw, int oldh)
    

    If you need to know the size just after inflate you can try to measure view manually: so call measure(...) than layout(...) and then getMeasuredWidth()/getMeasuredHeight should return the correct size. But this is more tricky, don't use it if you're not sure how it works.

提交回复
热议问题