onMeasure(): wrap_content, how do I know the size to wrap?

后端 未结 2 528
余生分开走
余生分开走 2021-02-01 08:12

I have made a custom View with onDraw() overridden that draws a bitmap on the canvas. When I specify that I want it wrap_content in the layout file it still fills u

2条回答
  •  旧巷少年郎
    2021-02-01 08:53

    If you can't measure the bitmap prior to the onMeasure call, then you could return a size of zero until the Bitmap is loaded. Once it is loaded, invalidate the parent ViewGroup to force another measure (can't remember if invalidate() on the View itself will force an onMeasure).

提交回复
热议问题