我有一个自定义视图,它是一个圆。这是我的CircleView的代码:
public class CircleView extends View {
private static final int START_ANGLE_POINT = 90;
private final Paint paint;
private final RectF rect;
private float angle;
public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
final int strokeWidth = 40;
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(strokeWidth);
//Circle color
paint.setColor(Color.RED);
rect = new RectF(strokeWidth, strokeWidth, 1000 + strokeWidth, 1000 + strokeWidth);
//Initial angle is zero
angle = 0;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawArc(rect, START_ANGLE_POINT, angle, false, paint);
}
public float getAngle() {
return angle;
}
public void setAngle(float angle) {
this.angle = angle;
} }
这是我在活动的xml布局中声明它的方式:
<com.my_package.ui.recording.CircleView
android:id="@+id/circleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
所有标准内容。这是我的自定义图片的样子
现在,我要将imageView放置在circleView的中央吗?有人知道我该怎么做到吗?
谢谢。