Skip to content

Commit 8cea618

Browse files
committed
Fix buttons rotating
1 parent 48cb1e5 commit 8cea618

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

circle-menu/src/main/java/com/ramotion/circlemenu/CircleMenuView.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,17 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
257257
final Rect buttonRect = new Rect();
258258
mMenuButton.getContentRect(buttonRect);
259259

260-
mRingView.setX(getWidth() / 2 - mRingView.getWidth() / 2);
261-
mRingView.setY(getHeight() / 2 - mRingView.getHeight() / 2);
260+
mRingView.setX(getWidth() / 2f - mRingView.getWidth() / 2f);
261+
mRingView.setY(getHeight() / 2f - mRingView.getHeight() / 2f);
262262
mRingView.setStrokeWidth(buttonRect.width());
263263

264264
if (mDistance == -1) {
265265
mDistance = buttonRect.width() * 1.5f;
266266
}
267267

268268
final LayoutParams lp = (LayoutParams) mRingView.getLayoutParams();
269-
lp.width = (int) mDistance * 2;
270-
lp.height = (int) mDistance * 2;
269+
lp.width = (int) (mDistance * 2);
270+
lp.height = (int) (mDistance * 2);
271271
mRingView.setLayoutParams(lp);
272272
}
273273

@@ -298,24 +298,23 @@ public void onAnimationEnd(Animator animation) {
298298

299299
private Animator getButtonClickAnimation(final @NonNull FloatingActionButton button) {
300300
final int buttonNumber = mButtons.indexOf(button) + 1;
301-
final int stepAngle = 360 / mButtons.size();
302-
final int startAngle = -90 - stepAngle + stepAngle * buttonNumber;
303-
304-
final Rect buttonRect = new Rect();
305-
mMenuButton.getContentRect(buttonRect);
301+
final float stepAngle = 360f / mButtons.size();
302+
final float startAngle = -90 - stepAngle + stepAngle * buttonNumber;
306303

307304
final float x = (float) Math.cos(Math.toRadians(startAngle)) * mDistance;
308305
final float y = (float) Math.sin(Math.toRadians(startAngle)) * mDistance;
309306

310-
button.setPivotX(button.getPivotX() - x);
311-
button.setPivotY(button.getPivotY() - y);
307+
final float pivotX = button.getPivotX();
308+
final float pivotY = button.getPivotY();
309+
button.setPivotX(pivotX - x);
310+
button.setPivotY(pivotY - y);
312311

313312
final ObjectAnimator rotateButton = ObjectAnimator.ofFloat(button, "rotation", 0f, 360f);
314313
rotateButton.addListener(new AnimatorListenerAdapter() {
315314
@Override
316315
public void onAnimationEnd(Animator animation) {
317-
button.setPivotX(buttonRect.width() / 2);
318-
button.setPivotY(buttonRect.height() / 2);
316+
button.setPivotX(pivotX);
317+
button.setPivotY(pivotY);
319318
}
320319
});
321320

0 commit comments

Comments
 (0)