Last active
December 15, 2016 02:23
-
-
Save ueno-yuhei/75fbda485281bb52e865 to your computer and use it in GitHub Desktop.
使いやすいシンプルな円を描くView ref: http://qiita.com/ueno-yuhei/items/c96bb7ac67aaaddcb261
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
circleView.setColor(R.color.white); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<test.ui.widget.CircleView | |
android:id="@+id/circle_view" | |
android:layout_width="48dp" | |
android:layout_height="48dp" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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