如果你想要在你的界面上画个扇形,使用的平时的控件是没有这个功能的,这时候我们就可以使用自定义view来绘制扇形
下面,我们来学习一下怎么使用自定义view来绘制:
一:创建一个类
一:我们先创建一个类,继承自View,然后重写两个构造方法
//我们调的
public _view(Context context) {
super(context);
}
//系统调的
public _view(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
为什么要创建两个呢?
第一个是为了供我们调用的,第二个则是android系统调用的。
二:重写方法:
//测量
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
//视图
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
然后再onDraw方法里面开始绘制。
二:开始绘制
先创建