我创建了一个自定义视图,我想在其中绘制一系列正方形,正方形的边取决于分配给视图的尺寸,因此在onMeasure()
检查模式和大小后的方法中,我调用 setMeasuredDimension (width, height) . 现在在 setMeasuredDimension 之后执行操作是正确的
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
/*******/
setMeasuredDimension(width,height);
squareSize = width / rows;
}