Android paint issue on different API

android, android-canvas, paint

Solution

Well it seems your app is hardware accelerated and in this mode some features like `setStrokeCap()` (for lines) are not supported, Have a look: http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported

Just disable hardware acceleration and try again. This is how you disable it:

<application android:hardwareAccelerated="false" ...>

Problem

I am having issues working with Paint for different API's for Android. The user is supposed to be able to draw letters on an area, which works fine on API 8 and 10, but for API 16 and 17, the lines look very different. I will show using images. This is how it's supposed to look, API 8. This is how it looks on API 16. Here is my code for the draw view: ``` public class TouchDrawView extends View { private Paint mPaint; private ArrayList<Point> mPoints; private ArrayList<ArrayList<Point>> mStrokes; public TouchDrawView(Context context) { super(context); mPoints = new ArrayList<Point>(); mStrokes = new ArrayList<ArrayList<Point>>(); mPaint = createPaint(Color.BLACK, 14); } @Override public void onDraw(Canvas c) { super.onDraw(c); for(ArrayList<Point> points: mStrokes) { drawStroke(points, c); } drawStroke(mPoints, c); } @Override public boolean onTouchEvent(MotionEvent event) { if(event.getActionMasked() == MotionEvent.ACTION_MOVE) { mPoints.add(new Point((int) event.getX(), (int) event.getY())); this.invalidate(); } if(event.getActionMasked() == MotionEvent.ACTION_UP) { mStrokes.add(mPoints); mPoints = new ArrayList(); } return true; } private void drawStroke(ArrayList stroke, Canvas c) { if (stroke.size() > 0) { Point p0 = (Point)stroke.get(0); for (int i = 1; i < stroke.size(); i++) { Point p1 = (Point)stroke.get(i); c.drawLine(p0.x, p0.y, p1.x, p1.y, mPaint); p0 = p1; } } } public void clear() { mPoints.clear(); mStrokes.clear(); this.invalidate(); } private Paint createPaint(int color, float width) { Paint temp = new Paint(); temp.setStyle(Paint.Style.FILL_AND_STROKE); temp.setAntiAlias(true); temp.setColor(color); temp.setStrokeWidth(width); temp.setStrokeCap(Paint.Cap.ROUND); return temp; } } ```

Original source