@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
visibleWidth = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
Log.i(TAG, "onMeasure: [width = " + visibleWidth + ", height = " + height + "]");
int realWidth = 0;
int realHeight = 0;
ViewGroup.LayoutParams params = getLayoutParams();
if (xLabels != null && xLabels.length > 0)
realWidth = (int) (getPaddingLeft() + getPaddingRight() + xSpace * (xLabels.length - 1) + .5f);
if (yLabels != null && yLabels.length > 0)
realHeight = (int) (getPaddingTop() + getPaddingBottom() + ySpace * (yLabels.length - 1) + 0.5f);
if (params.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(realWidth, MeasureSpec.EXACTLY);
} else {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(Math.max(visibleWidth, realWidth), MeasureSpec.EXACTLY);
}
if (params.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(realHeight, MeasureSpec.EXACTLY);
} else {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(Math.max(height, realHeight), MeasureSpec.EXACTLY);
int yCount = yLabels == null ? 0 : yLabels.length;
yCount = Math.max(1, yCount);
ySpace = height / yCount;
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}