I have searched for answers regarding this but haven't found a solution. So i am requesting help here. I am creating a custom View. I have overridden onMeasure. Code given Below.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int widthSize,heightSize;
int measureWidthSpec = MeasureSpec.getMode(widthMeasureSpec);
int measureHeightSpec = MeasureSpec.getMode(heightMeasureSpec);
widthSize = getCircleWidth(measureWidthSpec, MeasureSpec.getSize(widthMeasureSpec));
heightSize = getCircleHeight(measureHeightSpec,MeasureSpec.getSize(heightMeasureSpec));
int circleSize = Math.min(widthSize,heightSize);
setMeasuredDimension(circleSize, circleSize);
Log.d(TAG, "View Measured and ViewDimension : " + heightSize + " " + MeasureSpec.getSize(widthMeasureSpec));
}
When requesting the size here using MeasureSpec.getSize(widthMeasureSpec), 0 is returned. But for the height i get a value of 67. The getCircleWidth() and getCircleHeight are methods used to fix values according to the specMode. The part of the layout xml file where i declare my view is below.
<com.example.raaja.circleview.CircleView
android:id="@+id/CircleView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/textView"
android:layout_toRightOf="@+id/textView"
circle:circleColor="#5dade2"
circle:innerCircleColor="#2874a6"
circle:numberTextColor="#b3b6b7"
/>
Could anyone help me find why the value 0 is returned. Also the onDraw is not called as i fix a min value in setMeasuredDimension().