标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package
com.phodev.andtools.widget; import
android.content.Context; import
android.graphics.Canvas; import
android.graphics.Color; import
android.graphics.Paint; import
android.graphics.PorterDuff; import
android.graphics.PorterDuffXfermode; import
android.graphics.RectF; import
android.util.AttributeSet; import
android.widget.ImageView; /** *
圆角ImageView *
*
@author skg *
*/ public
class
RoundImageView extends
ImageView { public
RoundImageView(Context context, AttributeSet attrs) { super (context,
attrs); init(); } public
RoundImageView(Context context) { super (context); init(); } private
final
RectF roundRect = new
RectF(); private
float
rect_adius = 6 ; private
final
Paint maskPaint = new
Paint(); private
final
Paint zonePaint = new
Paint(); private
void
init() { maskPaint.setAntiAlias( true ); maskPaint.setXfermode( new
PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // zonePaint.setAntiAlias( true ); zonePaint.setColor(Color.WHITE); // float
density = getResources().getDisplayMetrics().density; rect_adius
= rect_adius * density; } public
void
setRectAdius( float
adius) { rect_adius
= adius; invalidate(); } @Override protected
void
onLayout( boolean
changed, int
left, int
top, int
right, int
bottom) { super .onLayout(changed,
left, top, right, bottom); int
w = getWidth(); int
h = getHeight(); roundRect.set( 0 ,
0 ,
w, h); } @Override public
void
draw(Canvas canvas) { canvas.saveLayer(roundRect,
zonePaint, Canvas.ALL_SAVE_FLAG); canvas.drawRoundRect(roundRect,
rect_adius, rect_adius, zonePaint); // canvas.saveLayer(roundRect,
maskPaint, Canvas.ALL_SAVE_FLAG); super .draw(canvas); canvas.restore(); } } |
标签:
原文地址:http://blog.csdn.net/u014311077/article/details/42645587