package myapplication21.lum.com.mycanvas;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class MyView extends View {
String TAG = "lum_ : ";
Paint paint;
public MyView(Context context) {
super(context);、(http://www.my516.com)
Log.i(TAG,"1");
}
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
Log.i(TAG,"2");
//就是通过修改画笔的一些参数设置
paint = new Paint(); //新建一个画笔对象
paint.setAntiAlias(true);//抗锯齿功能
paint.setColor(Color.RED); //设置画笔颜色
paint.setStyle(Paint.Style.STROKE);//设置填充样式 中空
paint.setStrokeWidth(10);//设置画笔宽度 ,单位px
}
public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
Log.i(TAG,"3");
}
public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
Log.i(TAG,"4");
}
protected void onDraw(Canvas canvas) {
// 在这里进行创建自定义组件的绘制
}
}
---------------------