Capture Layout resize before API 11

后端 未结 2 1210
情歌与酒
情歌与酒 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.

    0 讨论(0)
  • 2021-01-06 10:14

    After hours that I could not find anything, I wrote this message and immediately discovered this: How to retrieve the dimensions of a view?

    0 讨论(0)
提交回复
热议问题