// using a custom view, you can draw using path primitives:
private Paint mPaint; // paint object private Path mPathGrid; // path object @Override protected void onDraw(Canvas canvas) { if (mPaint == null) mPaint = new Paint(); // cache your paint object if (mPathGrid == null) mPathGrid = new Path(); // and your path mPaint.setStyle(Paint.Style.FILL); mPaint.setAntiAlias(true); // a white arrow pointing down mPaint.setColor(Color.WHITE); mPaint.setStrokeWidth(2); mPathGrid.reset(); mPathGrid.moveTo(100.0, 100.0); // 100,100 is starting point of path // "draw" the outline of your arrow... play "connect the dots"... mPathGrid.lineTo(100.0 + 10.0f, 100.0); mPathGrid.lineTo(100.0 + 10.0f, 100.0 - 5.0f); mPathGrid.lineTo(100.0 + 13.0f, 100.0 - 5.0f); mPathGrid.lineTo(100.0 + 10.0f, 100.0 - 8.0f); mPathGrid.lineTo(100.0 + 7.0f, 100.0 - 5.0f); mPathGrid.lineTo(100.0 + 10.0f, 100.0 - 5.0f); canvas.drawPath(mPathGrid, mPaint); super.onDraw(canvas); }
I saw this in your code:
for(int i=1; i<ArrayList_X.size(); i++) { Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG); myPaint.setStrokeWidth(8); myPaint.setColor(0xffff0000);
don't create new Paint objects in a loop like this, you only need one! And you only need to set properties such as stroke width, color, etc. Once.
source share