canvas (원)

android 2015. 10. 16. 15:37 |

public class ShapeActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
//setContentView(R.layout.activity_shape);

/* //리소스test
//Textview에서 리소스 가져온다
TextView textView =(TextView)findViewById(R.id.text_view);
//Textview의 문자열을 해달 리소스ID의 문자열로 변경한다
textView.setText(R.string.sample_string);
//TextView의 배경색을 해당 Color리소스로 적용한다.
textView.setBackground(R.color.RED);*/
}

private class MyView extends View{

public MyView(Context context){
super(context);
}
@Override
protected void onDraw(Canvas canvas){
canvas.drawColor(Color.WHITE);
Paint paint = new Paint();
RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());

//Example values
int mRadius = 300;
rect.set(getWidth() / 2 - mRadius, getHeight() / 2 - mRadius, getWidth() / 2 + mRadius, getHeight() / 2 + mRadius);

Paint p1 = new Paint(Paint.ANTI_ALIAS_FLAG);
Paint p2 = new Paint(Paint.ANTI_ALIAS_FLAG);
Paint p3 = new Paint(Paint.ANTI_ALIAS_FLAG);

p1.setColor(Color.RED);
p2.setColor(Color.BLUE);
p3.setColor(Color.YELLOW);

canvas.drawArc(rect, 0, 60, true, p1);
canvas.drawArc(rect, 60, 60, true, p2);
canvas.drawArc(rect, 120, 60, true, p3);
canvas.drawArc(rect, 180, 60, true, p1);
canvas.drawArc(rect, 240, 60, true, p2);
canvas.drawArc(rect, 300, 60, true, p3);
canvas.rotate(180, getWidth()/2, getHeight()/2);
//canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, canvas.getWidth()/3,p1);



}
}


'android' 카테고리의 다른 글

생명주기(작성중)  (0) 2015.10.28
안드로이드 스터디 내용 정리  (0) 2015.10.28
리소스에 대해서 - Color  (0) 2015.10.13
리소스에 대해서 - Value  (0) 2015.10.13
[안드로이드] 룰렛  (2) 2015.09.29
Posted by 양승아
: