@@ -22,6 +22,7 @@ The MIT License (MIT)
2222package com .king .view .radarview ;
2323
2424import android .animation .ValueAnimator ;
25+ import android .annotation .TargetApi ;
2526import android .content .Context ;
2627import android .content .res .TypedArray ;
2728import android .graphics .Canvas ;
@@ -31,6 +32,7 @@ The MIT License (MIT)
3132import android .graphics .Shader ;
3233import android .graphics .SweepGradient ;
3334import android .graphics .Typeface ;
35+ import android .os .Build ;
3436import android .support .annotation .Nullable ;
3537import android .support .annotation .StringRes ;
3638import android .text .TextUtils ;
@@ -207,9 +209,17 @@ public RadarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr
207209 init (context ,attrs );
208210 }
209211
212+ @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
213+ public RadarView (Context context , @ Nullable AttributeSet attrs , int defStyleAttr , int defStyleRes ) {
214+ super (context , attrs , defStyleAttr ,defStyleRes );
215+ init (context ,attrs );
216+ }
217+
218+
219+
210220 private void init (Context context ,AttributeSet attrs ) {
211221
212- mPaint = new Paint ();
222+ mPaint =new Paint ();
213223 mMatrix = new Matrix ();
214224
215225 TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .RadarView );
@@ -265,27 +275,31 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
265275 int width = measureHandler (widthMeasureSpec ,defaultWidth );
266276 int height = measureHandler (heightMeasureSpec ,defaultHeight );
267277
268- setMeasuredDimension (width ,height );
269278 //圆心坐标
270- mCircleCenterX = (getWidth () + getPaddingLeft () - getPaddingRight ())/ 2.0f ;
271- mCircleCenterY = (getHeight () + getPaddingTop () - getPaddingBottom ())/ 2.0f ;
279+ mCircleCenterX = (width + getPaddingLeft () - getPaddingRight ())/ 2.0f ;
280+ mCircleCenterY = (height + getPaddingTop () - getPaddingBottom ())/ 2.0f ;
272281
273282 //外圆半径
274- mRadius = (getWidth () - getPaddingLeft () - getPaddingRight () - mOutsideStrokeWidth ) / 2.0f ;
283+ mRadius = (width - getPaddingLeft () - getPaddingRight () - mOutsideStrokeWidth ) / 2.0f ;
275284 //内院的半径 为外援半径的1/3
276285 mInsideRadius = mRadius / 3 ;
277286
287+ setMeasuredDimension (width ,height );
288+
278289 }
279290
280- private int measureHandler (int measureSpec ,int defaultSize ){
291+
292+ private int measureHandler (int measureSpec , int defaultSize ){
281293
282294 int result = defaultSize ;
283295 int measureMode = MeasureSpec .getMode (measureSpec );
284296 int measureSize = MeasureSpec .getSize (measureSpec );
285- if (measureMode == MeasureSpec .EXACTLY ){
286- result = measureSize ;
297+ if (measureMode == MeasureSpec .UNSPECIFIED ){
298+ result = defaultSize ;
287299 }else if (measureMode == MeasureSpec .AT_MOST ){
288300 result = Math .min (defaultSize ,measureSize );
301+ }else {
302+ result = measureSize ;
289303 }
290304 return result ;
291305 }
0 commit comments