Problem with Android paint on different APIs

I have problems with Paint for different APIs for Android.

The user should be able to draw letters in an area that works fine on APIs 8 and 10, but for APIs 16 and 17, the lines look completely different. I will show how to use images.

Here's what it should look like, API 8 .

Here's how it looks on API 16 .

Here is my code for viewing a draw:

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; } } 
+4
source share
1 answer

Well, it looks like your application is hardware accelerated, and in this mode some functions like setStrokeCap() (for strings) are not supported, see: http://developer.android.com/guide/topics/graphics/hardware-accel. html # unsupported

Just turn off hardware acceleration and try again. Here's how you turn it off:

 <application android:hardwareAccelerated="false" ...> 
+3
source

Source: https://habr.com/ru/post/1495031/


All Articles