@@ -51,13 +51,13 @@ public class CircleMenu extends View {
5151
5252 private static final int MAX_SUBMENU_NUM = 8 ;
5353
54- private final int partSize = dip2px ( 20 ) ;
54+ private final int shadowRadius = 5 ;
5555
56- private final int iconSize = partSize * 4 / 5 ;
56+ private int partSize ;
5757
58- private final float circleMenuRadius = partSize * 3 ;
58+ private int iconSize ;
5959
60- private final int shadowRadius = 5 ;
60+ private float circleMenuRadius ;
6161
6262 private int itemNum ;
6363
@@ -117,21 +117,10 @@ public CircleMenu(Context context, AttributeSet attrs, int defStyleAttr) {
117117
118118 private void init () {
119119 initTool ();
120-
121- centerX = partSize * 5 ;
122- centerY = centerX ;
123-
124- path .addCircle (centerX , centerY , circleMenuRadius , Path .Direction .CW );
125- pathMeasure .setPath (path , true );
126- pathLength = pathMeasure .getLength ();
127-
128120 mainMenuColor = Color .parseColor ("#CDCDCD" );
129121 subMenuColorList = new ArrayList <>();
130122 subMenuDrawableList = new ArrayList <>();
131123 menuRectFList = new ArrayList <>();
132-
133- RectF mainMenuRectF = new RectF (centerX - partSize , centerY - partSize , centerX + partSize , centerY + partSize );
134- menuRectFList .add (mainMenuRectF );
135124 }
136125
137126 private void initTool () {
@@ -152,8 +141,43 @@ private void initTool() {
152141
153142 @ Override
154143 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
155- int measureSize = partSize * 5 * 2 ;
156- setMeasuredDimension (measureSize , measureSize );
144+ int widthMode = MeasureSpec .getMode (widthMeasureSpec );
145+ int heightMode = MeasureSpec .getMode (heightMeasureSpec );
146+
147+ int width = MeasureSpec .getSize (widthMeasureSpec );
148+ int height = MeasureSpec .getSize (heightMeasureSpec );
149+
150+ int measureWidthSize = width , measureHeightSize = height ;
151+
152+ if (widthMode == MeasureSpec .AT_MOST ) {
153+ measureWidthSize = dip2px (20 ) * 10 ;
154+ }
155+
156+ if (heightMode == MeasureSpec .AT_MOST ) {
157+ measureHeightSize = dip2px (20 ) * 10 ;
158+ }
159+ setMeasuredDimension (measureWidthSize , measureHeightSize );
160+ }
161+
162+ @ Override
163+ protected void onSizeChanged (int w , int h , int oldw , int oldh ) {
164+ super .onSizeChanged (w , h , oldw , oldh );
165+
166+ int minSize = Math .min (getMeasuredWidth (), getMeasuredHeight ());
167+
168+ partSize = minSize / 10 ;
169+ iconSize = partSize * 4 / 5 ;
170+ circleMenuRadius = partSize * 3 ;
171+
172+ centerX = getMeasuredWidth () / 2 ;
173+ centerY = getMeasuredHeight () / 2 ;
174+
175+ path .addCircle (centerX , centerY , circleMenuRadius , Path .Direction .CW );
176+ pathMeasure .setPath (path , true );
177+ pathLength = pathMeasure .getLength ();
178+
179+ RectF mainMenuRectF = new RectF (centerX - partSize , centerY - partSize , centerX + partSize , centerY + partSize );
180+ menuRectFList .add (mainMenuRectF );
157181 }
158182
159183 @ Override
0 commit comments