From 13e90f7963a27fb85b76fd313efe972dd7c145df Mon Sep 17 00:00:00 2001 From: Berend Date: Fri, 3 Nov 2017 12:10:48 +0100 Subject: [PATCH] Added support for offset when gravity is Center --- .../java/q/rorbin/badgeviewdemo/MainActivity.java | 4 ++-- app/src/main/res/layout/activity_main.xml | 8 ++++---- .../src/main/java/q/rorbin/badgeview/QBadgeView.java | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/q/rorbin/badgeviewdemo/MainActivity.java b/app/src/main/java/q/rorbin/badgeviewdemo/MainActivity.java index 84e6bda..75a4a23 100644 --- a/app/src/main/java/q/rorbin/badgeviewdemo/MainActivity.java +++ b/app/src/main/java/q/rorbin/badgeviewdemo/MainActivity.java @@ -159,8 +159,8 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { for (Badge badge : badges) { if (seekBar == seekBar_offsetx || seekBar == seekBar_offsety) { - int x = seekBar_offsetx.getProgress(); - int y = seekBar_offsety.getProgress(); + int x = seekBar_offsetx.getProgress()-(seekBar_offsetx.getMax()/2); + int y = seekBar_offsety.getProgress()-(seekBar_offsety.getMax()/2); tv_offsetx.setText("GravityOffsetX : " + x); tv_offsety.setText("GravityOffsetY : " + y); badge.setGravityOffset(x, y, true); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8e27069..8820ad8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -184,8 +184,8 @@ android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginTop="10dp" - android:max="20" - android:progress="1" /> + android:max="40" + android:progress="20" /> @@ -209,8 +209,8 @@ android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginTop="10dp" - android:max="20" - android:progress="1" /> + android:max="40" + android:progress="20" /> diff --git a/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java b/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java index c96a30f..caaf3cd 100644 --- a/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java +++ b/badgeviewlib/src/main/java/q/rorbin/badgeview/QBadgeView.java @@ -525,24 +525,24 @@ private void findBadgeCenter() { mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f); break; case Gravity.CENTER: - mBadgeCenter.x = mWidth / 2f; - mBadgeCenter.y = mHeight / 2f; + mBadgeCenter.x = (mWidth / 2f) + mGravityOffsetX; + mBadgeCenter.y = (mHeight / 2f) + mGravityOffsetY; break; case Gravity.CENTER | Gravity.TOP: - mBadgeCenter.x = mWidth / 2f; + mBadgeCenter.x = (mWidth / 2f) + mGravityOffsetX; mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f; break; case Gravity.CENTER | Gravity.BOTTOM: - mBadgeCenter.x = mWidth / 2f; + mBadgeCenter.x = (mWidth / 2f) + mGravityOffsetX; mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f); break; case Gravity.CENTER | Gravity.START: mBadgeCenter.x = mGravityOffsetX + mBadgePadding + rectWidth / 2f; - mBadgeCenter.y = mHeight / 2f; + mBadgeCenter.y = (mHeight / 2f) + mGravityOffsetY; break; case Gravity.CENTER | Gravity.END: mBadgeCenter.x = mWidth - (mGravityOffsetX + mBadgePadding + rectWidth / 2f); - mBadgeCenter.y = mHeight / 2f; + mBadgeCenter.y = (mHeight / 2f) + mGravityOffsetY; break; } initRowBadgeCenter();