Created Custom view and overridden it's onDraw().
- Without Overriding onMeasure() canvas occupies the entire screen of device.
- Overriding onMeasure(), canvas is re-sized to dimension passed to setMeasuredDimension().
Hence we can resize the canvas for sure and It has to be done in onMeasure().
I want to re-size the canvas of my custom view to the size specified in it's LayoutParams(XML or Java)
Now in need of method/attribute which will return size parameters mentioned in LayoutParams to pass inside setMeasuredDimension().
getWidth()/getHeight() - value is set only after first pass of onMeasure()
getLayoutParams().width/getLayoutParams().height - Not sure when this value will return valid values (setting params programatically gives value '-1')
getMeasuredWidth()/getMeasuredHeight() - returns size parameter specified in layout params only if it has been set in XML and not if is programatically assigned.
Is there any other gurantee method which will returns width & height that has been set in layout params of customview OR getMeasuredWidth()/getMeasuredHeight() is the correct choice to pass in setMeasureDimensions()?
Might be duplicate of Android Custom View Size
LayoutParamsare sent to theonMeasuremethod, it's your job to override it in such way that it reflects those values. - user