1) RectF의 생성자


public RectF (float left, float top, float right, float bottom)

⇒ Create a new rectangle with the specified coordinates.
Note: no range checking is performed, so the caller must ensure that left <= right and top <= bottom.

주어진 좌표 값을 이용해서 새로운 사각형을 만드는 클래스이다. 주의할 점은 left 값이 right 값보다 작아야 되는데 이러한 값의 범위가 올바른지는 체크해야 한다는 이야기가 있고요.


Parameters

left : The X coordinate of the left side of the rectangle

top : The Y coordinate of the top of the rectangle

right : The X coordinate of the right side of the rectangle

bottom : The Y coordinate of the bottom of the rectangle


⇒ 사각형 그리는 클래스


2) Path의 메소드

public void arcTo (RectF oval, float startAngle, float sweepAngle)

⇒ Append the specified arc to the path as a new contour. If the start of the path is different from the path's current last point, then an automatic lineTo() is added to connect the current contour to the start of the arc. However, if the path is empty, then we call moveTo() with the first point of the arc.

원호를 그릴 경로(path)를 미리 지정해 놓는 메소드이다. 


Parameters

oval : The bounds of oval defining shape and size of the arc

       : 원호를 그릴 영역, 원호의 크기를 결정하는 경계선 역할

startAngle : Starting angle (in degrees) where the arc begins

                : 원호가 시작되는 지점. 각도로 표시

sweepAngle : Sweep angle (in degrees) measured clockwise

                  : 시계방향으로 원호를 그리는 각도 지정


⇒ 그림을 그릴 경로를 미리 지정. Canvas 클래스의 drawPath()를 이용해서 Path로 지정된 경로를 따라 그리기를 한다.


3) Canvas의 메소드 

public void drawPath (Path path, Paint paint)

⇒ Draw the specified path using the specified paint. The path will be filled or framed based on the Style in the paint. 앞에서 설정된 경로(path)대로 그림을 실제 그리는 역할


Parameters

path : The path to be drawn

paint : The paint used to draw the path



예제)

RectF rf = new RectF();


//좌에서 우로 50만큼 이동된 x축 위치와 위에서 아래쪽으로           

//50만큼 이동된 y축 위치와 좌에서 우로 100만큼 이동된 

//x축 위치와 위에서 아래쪽으로 100만큼 이동된 y축 위치를 잇는 

//사각형. 이 영역이 그림이 그려질 영역이다.

rf.set(50, 50, 100, 100);                      


Path path = new Path();


//그림을 그릴 path를 지정해 두고 나중에 drawPath()로 이 

//path를 따라 원호를 그린다.

//원호의 크기는 두 번째, 세 번째 인자가 지정하는 크기만큼 그린다.

//rf는 그림을 그릴 영역이고, 0은 그림을 시작할 위치인데 각도로 

//표시한다. 시계로 3시 지점이 0도이고

//6시 지점이 90도이고 9시 지점이 180도이고 12시 지점이 270도

//이다. 방향은 시계 방향으로 돌아가는 방식으로 각도를 지정한다.

path.arcTo(rf, 0, 180); 

                                 

public void onDraw(Canvas canvas) 

{

   Paint paint = new Paint();

   paint.setFlags(Paint.ANTI_ALIAS_FALG); 

   paint.setStrokeWidth(2); //선의 굵기를 2로 지정


   RectF rf = new RectF();

   rf.set(50, 50, 100, 100);


   Path path = new Path();


   //3시 지점에서 시작해서 시계 방향으로 9시 지점까지 

   //원호를 그린다.

   path.arcTo(rf, 0, 180); 

                                     

   canvas.drawPath(path, paint);

}




+ Recent posts