private Paint mPaint;
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private float mStartX;
private float mStartY;
private float mStopX;
private float mStopY;
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
mCanvas = new Canvas();
mPaint = new Paint();
mPath = new Path();
mBitmap = Bitmap.createBitmap(750, 750, Config.ARGB_8888);
// 设置mCanvas将会绘制到内存中的mBitmap上
mCanvas.setBitmap(mBitmap);
mPaint.setColor(Color.BLACK);
//设置画笔风格
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
//反锯齿
mPaint.setAntiAlias(true);
mPaint.setDither(true);
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.xuqinjun.helloll.MyView
android:id="@+id/myview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="800dp"
android:height="480dp"
/>
</LinearLayout>
没有图片红色部分就会出现该异常 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xuqinjun.hello01/com.xuqinjun.helloll.MainActivity}:android.view.InflateException: Binary XML file line #7: Error inflating class com.xuqinjun.helloll.MyView