Skip to content

Commit 8d8b16e

Browse files
author
dingrui
committed
解决边框颜色不能改变 bug
1 parent 7172a4d commit 8d8b16e

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

imagelib/src/main/java/com/exampleenen/ruedy/imagelib/widget/IdentityImageView.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class IdentityImageView extends ViewGroup {
2929
private double angle = 45; //标识角度大小
3030
private boolean isprogress;//是否可以加载进度条,必须设置为true才能开启
3131
private int progressCollor;//进度条颜色
32-
private int borderColor;//边框颜色
32+
private int borderColor = 0;//边框颜色
3333
private int borderWidth;//边框、进度条宽度
3434
private TextView textView;//标识符为文字,用的地方比较少
3535
private boolean hintSmallView;//标识符是否隐藏
@@ -39,7 +39,9 @@ public class IdentityImageView extends ViewGroup {
3939
private Drawable bigImage;//大图片
4040
private Drawable smallimage;//小图片
4141
private int setprogressColor = 0;//动态设置进度条颜色值
42+
private int setborderColor = 0;//动态设置边框颜色值
4243
private int totalwidth;
44+
4345
public IdentityImageView(Context context) {
4446
this(context, null);
4547
}
@@ -90,12 +92,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
9092
@Override
9193
protected void onDraw(Canvas canvas) {
9294
initPaint();
93-
if (isprogress) {
94-
drawProgress(canvas);
95-
}
9695
if (borderWidth > 0) {
9796
drawBorder(canvas);
9897
}
98+
if (isprogress) {
99+
drawProgress(canvas);
100+
}
101+
99102

100103
}
101104

@@ -105,12 +108,12 @@ protected void onDraw(Canvas canvas) {
105108
* @param canvas 画布
106109
*/
107110
private void drawBorder(Canvas canvas) {
108-
canvas.drawCircle(totalwidth/2, totalwidth/2, radius - borderWidth / 2, mBorderPaint);
111+
canvas.drawCircle(totalwidth / 2, totalwidth / 2, radius - borderWidth / 2, mBorderPaint);
109112
}
110113

111114
//画圆弧进度条
112115
private void drawProgress(Canvas canvas) {
113-
RectF rectf = new RectF(smallRadius+borderWidth / 2, smallRadius+borderWidth / 2, getWidth() -smallRadius- borderWidth / 2, getHeight()-smallRadius - borderWidth / 2);
116+
RectF rectf = new RectF(smallRadius + borderWidth / 2, smallRadius + borderWidth / 2, getWidth() - smallRadius - borderWidth / 2, getHeight() - smallRadius - borderWidth / 2);
114117
//定义的圆弧的形状和大小的范围,之所以减去圆弧的一半,是因为画圆环的高度时,
115118
// 原因就在于setStrokeWidth这个方法,并不是往圆内侧增加圆环宽度的,而是往外侧增加一半,往内侧增加一半。
116119
canvas.drawArc(rectf, (float) angle, progresss, false, mProgressPaint);
@@ -123,7 +126,11 @@ private void initPaint() {
123126
mBorderPaint.setStyle(Paint.Style.STROKE);
124127
mBorderPaint.setAntiAlias(true);
125128
}
126-
mBorderPaint.setColor(borderColor);
129+
if (setborderColor != 0) {
130+
mBorderPaint.setColor(getResources().getColor(setborderColor));
131+
}else {
132+
mBorderPaint.setColor(borderColor);
133+
}
127134
mBorderPaint.setStrokeWidth(borderWidth);
128135

129136
if (mProgressPaint == null) {
@@ -146,11 +153,11 @@ protected void onLayout(boolean b, int i, int i1, int i2, int i3) {
146153

147154
double cos = Math.cos(angle * Math.PI / 180);
148155
double sin = Math.sin(angle * Math.PI / 180);
149-
double left = totalwidth/2 + (radius * cos - smallRadius);
150-
double top = totalwidth/2 + (radius * sin - smallRadius);
156+
double left = totalwidth / 2 + (radius * cos - smallRadius);
157+
double top = totalwidth / 2 + (radius * sin - smallRadius);
151158
int right = (int) (left + 2 * smallRadius);
152159
int bottom = (int) (top + 2 * smallRadius);
153-
bigImageView.layout(smallRadius+borderWidth / 2, smallRadius+borderWidth / 2, totalwidth-smallRadius - borderWidth / 2, totalwidth-smallRadius - borderWidth / 2);
160+
bigImageView.layout(smallRadius + borderWidth / 2, smallRadius + borderWidth / 2, totalwidth - smallRadius - borderWidth / 2, totalwidth - smallRadius - borderWidth / 2);
154161
textView.layout((int) left, (int) top, right, bottom);
155162
smallImageView.layout((int) left, (int) top, right, bottom);
156163

@@ -305,7 +312,7 @@ public void setIsprogress(boolean b) {
305312
*/
306313
public void setBorderColor(int color) {
307314
if (color == borderColor) return;
308-
borderColor = color;
315+
setborderColor = color;
309316
requestLayout();
310317
invalidate();
311318

@@ -328,7 +335,6 @@ public void setProgressColor(int color) {
328335
*/
329336
public void setBorderWidth(int width) {
330337
if (width == borderWidth) return;
331-
;
332338
borderWidth = width;
333339
requestLayout();//重走onLayout方法
334340
invalidate();//重走onDraw方法

0 commit comments

Comments
 (0)