Skip to content

Instantly share code, notes, and snippets.

@ueno-yuhei
Last active December 15, 2016 02:23
Show Gist options
  • Save ueno-yuhei/75fbda485281bb52e865 to your computer and use it in GitHub Desktop.
Save ueno-yuhei/75fbda485281bb52e865 to your computer and use it in GitHub Desktop.
使いやすいシンプルな円を描くView ref: http://qiita.com/ueno-yuhei/items/c96bb7ac67aaaddcb261
public class CircleView extends View {
private Paint paint;
public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
}
public CircleView(Context context) {
super(context);
paint = new Paint();
}
public void setColor(int color){
paint.setColor(getResources().getColor(color));
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
paint.setAntiAlias(true);
canvas.drawCircle(canvas.getHeight() / 2, canvas.getHeight() / 2, (canvas.getWidth() / 2) - 2, paint);
}
}
circleView.setColor(R.color.white);
<test.ui.widget.CircleView
android:id="@+id/circle_view"
android:layout_width="48dp"
android:layout_height="48dp" />
CircleView circleView = (CircleView) view.findViewById(R.id.circle_view);
circleView.setColor(R.color.black);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment