Android graphics for different APIs
•
Android
I'm having trouble using different APIs for paint for Android
Users should be able to draw letters on an area, which works well on API 8 and 10, but for API 16 and 17, these lines look very different. I'll show you how to use images
That's what it should look like, API 8
This is what API 16 looks like
This is my drawing View Code:
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;
}
}
resolvent:
Well, it seems that your application is hardware accelerated. In this mode, some functions such as setstrokecap () (for lines) are not supported. Take a look: http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
Just disable hardware acceleration and try again. Here's how you disable it:
<application android:hardwareAccelerated="false" ...>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码