hi i want to draw path into canvas but it does not do anything, it does not draw the canvas either.
my code:
Path path = new Path();
Canvas canvas = new Canvas();
Paint paint = new Paint();
paint.setColor(Color.BLACK);
canvas.drawColor(Color.CYAN);
for (int i = 5; i < 50; i++)
{
path.setLastPoint(4, i - 1);
path.lineTo(4, i);
}
path.close();
for (int i = 0; i < 5; i++)
{
View iview = inflater.inflate(R.layout.linear_layout, null);
iview.findViewById(R.id.imageView1);//.setBackgroundColor(backgroundColors[i]);
ShapeDrawable mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(Color.YELLOW);
mDrawable.setBounds(10, 10, 15, 15);
canvas.drawPath(path, paint);
mDrawable.draw(canvas);
iview.draw(canvas);
realViewSwitcher.addView(iview);
}
it shows me only green color which is the default value of the view.backroundColor.
thanks
Canvasis just a “tool” for drawing over aBitmap. You need to associate them this way:However this only lets you draw on someBitmap. If you want to draw in the view, you have to do that in
onDraw(Canvas), using theCanvasyou’re provided with, which is already bound with the bitmap that is the real view’s drawing.To use
onDraw(), you have to make a custom View (that is, extend from someView).Then there is
SurfaceViewbut that’s another thing (and I don’t know much about it).