How can you tell when a layout has been drawn?

后端 未结 8 504
轻奢々
轻奢々 2020-11-22 08:07

I have a custom view that draws a scrollable bitmap to the screen. In order to initialize it, i need to pass in the size in pixels of the parent layout object. But during th

相关标签:
8条回答
  • 2020-11-22 08:40

    When onMeasure is called the view gets its measured width/height. After this, you can call layout.getMeasuredHeight().

    0 讨论(0)
  • 2020-11-22 08:47

    A really easy way is to simply call post() on your layout. This will run your code the next step, after your view has already been created.

    YOUR_LAYOUT.post( new Runnable() {
        @Override
        public void run() {
            int width  = YOUR_LAYOUT.getMeasuredWidth();
            int height = YOUR_LAYOUT.getMeasuredHeight(); 
        }
    });
    
    0 讨论(0)
提交回复
热议问题