본문 바로가기

안드로이드/코드

[#B2 DEPRECATED]RoundImageView.java

RoundImageView.java 소스코드입니다.

radius를 조정하여 원형에 가깝게 혹은 멀게 조절할 수 있습니다.

( 기본값 36.0f는 완전한 원형이며, 값이 낮아질수록 사각형에 가까워집니다. )


레이아웃에서 이미지뷰 대신 사용합니다.


SOURCE CODE


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
public class RoundImageView extends AppCompatImageView {
 
    public static float radius = 36.0f;
 
    public RoundImageView(Context context) {
        super(context);
    }
 
    public RoundImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
 
    public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
 
    @Override
    protected void onDraw(Canvas canvas) {
        Path clipPath = new Path();
        RectF rect = new RectF(00this.getWidth(), this.getHeight());
        clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
        canvas.clipPath(clipPath);
        super.onDraw(canvas);
    }
}
 
cs