From 567edd5fdcf99f45fa67d9dd464720642420070a Mon Sep 17 00:00:00 2001 From: woxingxiao Date: Tue, 3 Jan 2017 13:08:37 +0800 Subject: [PATCH] =?UTF-8?q?v1.6=EF=BC=9A=20=20=E2=91=A0=20deal=20with=20on?= =?UTF-8?q?SizeChanged=EF=BC=9B=20=20=E2=91=A1=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=94=B1java=E4=BB=A3=E7=A0=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=B1=9E=E6=80=A7=E7=9A=84bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/xw/repo/BubbleSeekBar.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java b/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java index 2bb88d2..ff45ec1 100644 --- a/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java +++ b/bubbleseekbar/src/main/java/com/xw/repo/BubbleSeekBar.java @@ -193,7 +193,15 @@ public BubbleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { mBubbleView.setProgressText(isShowProgressInFloat ? String.valueOf(getProgressInFloat()) : String.valueOf(getProgress())); + calculateRadiusOfBubble(); + } + + /** + * 根据min、max计算气泡半径 + */ + private void calculateRadiusOfBubble() { mPaint.setTextSize(mBubbleTextSize); + // 计算滑到两端气泡里文字需要显示的宽度,比较取最大值为气泡的半径 String text = mMin < 0 ? "-" + mMin : "" + mMin; mPaint.getTextBounds(text, 0, text.length(), mRectText); @@ -683,6 +691,9 @@ public void setMin(int min) { mMin = min; mDelta = mMax - mMin; + + calculateRadiusOfBubble(); + postInvalidate(); } @@ -691,7 +702,18 @@ public int getMax() { } public void setMax(int max) { + if (mMax == max || max < mMin) { + return; + } + mMax = max; + mDelta = mMax - mMin; + + if (mProgress > mMax) { + mProgress = mMax; + } + calculateRadiusOfBubble(); + postInvalidate(); } @@ -812,6 +834,11 @@ public void setSectionCount(int sectionCount) { if (mSectionCount <= 0 || mSectionCount > mMax - mMin) { mSectionCount = 10; } + if (mSectionCount > mDelta) { + isShowProgressInFloat = true; + + calculateRadiusOfBubble(); + } requestLayout(); } @@ -921,8 +948,16 @@ public boolean isShowProgressInFloat() { } public void setShowProgressInFloat(boolean showProgressInFloat) { + if (mSectionCount > mDelta) { + isShowProgressInFloat = true; + return; + } + if (isShowProgressInFloat != showProgressInFloat) { isShowProgressInFloat = showProgressInFloat; + + calculateRadiusOfBubble(); + postInvalidate(); } }