Skip to content

Commit 50d75b2

Browse files
committed
fix issue #23, #17. 支持自定义进度条圆角
1 parent cf0d2c8 commit 50d75b2

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ rsb_seekBarHeight|dimension|The height of the progress bar
3131
rsb_thumbSize|dimension|The size of the button
3232
rsb_cellMode|enum|Scale mode **number** according to the scale of the actual proportion of the distribution of the location *(markTextArray must be a number)* **other** bisects the current layout*(markTextArray can be any character)*
3333
rsb_seekBarMode| enum |One-way, two-way mode **single** like normal seekbar **range** Bidirectional selection SeekBar
34+
rsb_thumbRadius|dimension|The radius of the progress bar
3435

3536
## Usage
3637

@@ -45,7 +46,7 @@ rsb_seekBarMode| enum |One-way, two-way mode **single** like normal seekbar **ra
4546
}
4647

4748
dependencies {
48-
compile 'com.github.Jay-Goo:RangeSeekBar:v1.2.0'
49+
compile 'com.github.Jay-Goo:RangeSeekBar:v1.2.1'
4950
}
5051

5152
```
@@ -79,6 +80,7 @@ v1.0.7 | set the seekbar gravity center to make the layout easier
7980
v1.0.8 | fix issue #2, #3
8081
v1.1.0 | add progressHintMode and some color attrs setter
8182
v1.2.0 | thumbResId support custom drawable;Property name refactoring to prevent naming conflicts;adjust rsb_progressHintMode,add onStopTrackingTouch,onStartTrackingTouch Listeners
83+
v1.2.1 | fix issue #23, #17. add radius of progress
8284

8385
## [Blog](http://blog.csdn.net/google_acmer/article/details/54971421)
8486

README_ZH.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rsb_seekBarHeight|dimension|进度条的高度
2727
rsb_thumbSize|dimension|按钮的尺寸
2828
rsb_cellMode|enum|刻度模式 **number** 根据刻度的实际所占比例分配位置*(markTextArray中必须都为数字)* **other** 平分当前布局*(markTextArray可以是任何字符)*
2929
rsb_seekBarMode| enum |单向、双向模式 **single** 单向模式,只有一个按钮 **range** 双向模式,有两个按钮
30+
rsb_thumbRadius|dimension|进度条圆角
3031

3132
## Usage
3233

@@ -41,7 +42,7 @@ rsb_seekBarMode| enum |单向、双向模式 **single** 单向模式,只有一
4142
}
4243

4344
dependencies {
44-
compile 'com.github.Jay-Goo:RangeSeekBar:v1.2.0'
45+
compile 'com.github.Jay-Goo:RangeSeekBar:v1.2.1'
4546
}
4647

4748
```
@@ -74,6 +75,7 @@ v1.0.7 | 令seekbar布局居中,让你的布局和其他布局配合更简单
7475
v1.0.8 | 修复issue #2#3
7576
v1.1.0 | 添加进度提示模式属性,添加color 属性setter
7677
v1.2.0 | thumbResId支持自定义drawable;属性名重构,防止命名冲突;调整rsb_progressHintMode,新增onStopTrackingTouch,onStartTrackingTouch Listeners
78+
v1.2.1 | fix issue #23, #17. 支持自定义进度条圆角
7779

7880
## [博客讲解](http://blog.csdn.net/google_acmer/article/details/54971421)
7981

RangeSeekBar/src/main/java/com/jaygoo/widget/RangeSeekBar.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ public class RangeSeekBar extends View {
8585
private int mCursorTextHeight;
8686
private int mPartLength;
8787
private int heightNeeded;
88-
private int lineCorners;
8988
private int lineWidth;
9089

90+
//进度条圆角
91+
//radius of progress bar
92+
private float lineRadius;
93+
9194
//选择过的进度条颜色
9295
// the color of the selected progress bar
9396
private int colorLineSelected;
@@ -136,7 +139,8 @@ public class RangeSeekBar extends View {
136139
private Paint mMainPaint = new Paint();
137140
private Paint mCursorPaint = new Paint();
138141
private Paint mProgressPaint;
139-
private RectF line = new RectF();
142+
private RectF backgroundLineRect = new RectF();
143+
private RectF foregroundLineRect = new RectF();
140144
private SeekBar leftSB ;
141145
private SeekBar rightSB;
142146
private SeekBar currTouch;
@@ -172,6 +176,7 @@ public RangeSeekBar(Context context, AttributeSet attrs) {
172176
mThumbSize = (int)t.getDimension(R.styleable.RangeSeekBar_rsb_thumbSize,dp2px(context,26));
173177
mCellMode = t.getInt(R.styleable.RangeSeekBar_rsb_cellMode , 0);
174178
mSeekBarMode = t.getInt(R.styleable.RangeSeekBar_rsb_seekBarMode , 2);
179+
lineRadius = (int)t.getDimension(R.styleable.RangeSeekBar_rsb_lineRadius,-1);
175180

176181
if (mSeekBarMode == 2){
177182
leftSB = new SeekBar(-1);
@@ -205,8 +210,8 @@ public RangeSeekBar(Context context, AttributeSet attrs) {
205210
//Android7.0以上:onMeasure--->onSizeChanged
206211
lineTop = (int)mHintBGHeight + mThumbSize/2 -mSeekBarHeight/2 ;
207212
lineBottom = lineTop + mSeekBarHeight ;
208-
lineCorners = (int) ((lineBottom - lineTop) * 0.45f);
209-
213+
//default value
214+
if (lineRadius < 0) lineRadius = (int) ((lineBottom - lineTop) * 0.45f);
210215
}
211216

212217
@Override
@@ -242,7 +247,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
242247
lineLeft = DEFAULT_PADDING_LEFT_AND_RIGHT + getPaddingLeft();
243248
lineRight = w - lineLeft - getPaddingRight();
244249
lineWidth = lineRight - lineLeft;
245-
line.set(lineLeft, lineTop, lineRight, lineBottom);
250+
backgroundLineRect.set(lineLeft, lineTop, lineRight, lineBottom);
246251

247252
leftSB.onSizeChanged(lineLeft, lineBottom, mThumbSize, lineWidth, cellsCount > 1, mThumbResId, getContext());
248253
if (mSeekBarMode == 2) {
@@ -286,14 +291,22 @@ protected void onDraw(Canvas canvas) {
286291
//绘制进度条
287292
// draw the progress bar
288293
mMainPaint.setColor(colorLineEdge);
289-
canvas.drawRoundRect(line, lineCorners, lineCorners, mMainPaint);
294+
295+
canvas.drawRoundRect(backgroundLineRect, lineRadius, lineRadius, mMainPaint);
290296
mMainPaint.setColor(colorLineSelected);
297+
291298
if (mSeekBarMode == 2) {
292-
canvas.drawRect(leftSB.left + leftSB.widthSize / 2 + leftSB.lineWidth * leftSB.currPercent, lineTop,
293-
rightSB.left + rightSB.widthSize / 2 + rightSB.lineWidth * rightSB.currPercent, lineBottom, mMainPaint);
299+
foregroundLineRect.top = lineTop;
300+
foregroundLineRect.left = leftSB.left + leftSB.widthSize / 2 + leftSB.lineWidth * leftSB.currPercent;
301+
foregroundLineRect.right = rightSB.left + rightSB.widthSize / 2 + rightSB.lineWidth * rightSB.currPercent;
302+
foregroundLineRect.bottom = lineBottom;
303+
canvas.drawRoundRect(foregroundLineRect, lineRadius, lineRadius, mMainPaint);
294304
}else {
295-
canvas.drawRect(leftSB.left + leftSB.widthSize / 2 , lineTop,
296-
leftSB.left + leftSB.widthSize / 2 + leftSB.lineWidth * leftSB.currPercent, lineBottom, mMainPaint);
305+
foregroundLineRect.top = lineTop;
306+
foregroundLineRect.left = leftSB.left + leftSB.widthSize / 2 ;
307+
foregroundLineRect.right = leftSB.left + leftSB.widthSize / 2 + leftSB.lineWidth * leftSB.currPercent;
308+
foregroundLineRect.bottom = lineBottom;
309+
canvas.drawRoundRect(foregroundLineRect, lineRadius, lineRadius, mMainPaint);
297310
}
298311
if (mProgressHintMode == HINT_MODE_ALWAYS_SHOW){
299312
isShowProgressHint(leftSB, true);
@@ -455,7 +468,7 @@ protected void draw(Canvas canvas) {
455468
if (hintW < 1.5f * hintH) hintW = (int)(1.5f * hintH);
456469

457470
if (bmp != null) {
458-
canvas.drawBitmap(bmp, left, lineTop - bmp.getHeight() / 2, null);
471+
canvas.drawBitmap(bmp, left, lineTop + (mSeekBarHeight - bmp.getHeight()) / 2, null);
459472
if (isShowingHint) {
460473

461474
Rect rect = new Rect();

RangeSeekBar/src/main/res/values/attrs.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
other 平分当前布局(markTextArray可以是任何字符)
2828
-->
2929
<!--单向、双向模式 single 单向模式,只有一个按钮 range 双向模式,有两个按钮 -->
30+
<!--进度条圆角-->
3031

3132
<!-- ******************** 参数解释 ******************** -->
3233

@@ -61,7 +62,7 @@
6162
Other bisects the current layout (markTextArray can be any character)
6263
-->
6364
<!--One-way, two-way mode single one-way mode, there is only one button range bidirectional mode, two buttons -->
64-
65+
<!--the radius of progressbar-->
6566
<!-- ******************** Parameter Explanation ******************** -->
6667

6768

@@ -100,6 +101,6 @@
100101
<enum name="single" value="1"/>
101102
<enum name="range" value="2"/>
102103
</attr>
103-
104+
<attr name="rsb_lineRadius" format="dimension"/>
104105
</declare-styleable>
105106
</resources>

app/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@
7777
app:rsb_lineColorEdge="@color/colorSeekBarDefault"
7878
app:rsb_textPadding="17dp"
7979
app:rsb_cells="4"
80-
app:rsb_progressHintMode="alwaysHide"
8180
app:rsb_textSize="12sp"
82-
app:rsb_hintBGHeight="28dp"
83-
app:rsb_seekBarHeight="8dp"
81+
app:rsb_hintBGHeight="38dp"
82+
app:rsb_seekBarHeight="4dp"
8483
app:rsb_thumbSize="26dp"
8584
app:rsb_cellMode="other"
8685
app:rsb_seekBarMode="single"
86+
app:rsb_lineRadius="0dp"
8787
/>
8888

8989
</LinearLayout>

0 commit comments

Comments
 (0)