Drawing a line above the ImageView in android

Viewed 1293

I have a custom imageView, say MyImageView class and i am trying to draw some lines above it.

public class MyImageView extends ImageView
{

public MyImageView(Context context) {
    super(context);

    invalidate();
    // TODO Auto-generated constructor stub
}

public MyImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    invalidate();
}

public MyImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    invalidate();
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
    p.setColor(Color.BLACK);
    canvas.drawLine(0, 0, 100, 100, p);

    canvas.drawLine(0, 0, 20, 20, p);
    canvas.drawLine(20, 0, 0, 20, p);
    super.onDraw(canvas);


}
}

In my activity class i have set an image to that custom imageView with the help of a bitmap.

MyImageView imageView;
 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imageView=(MyImageView)findViewById(R.id.image);
    Bitmap dbitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dinkan);
    Bitmap bitmap = dbitmap.copy(Bitmap.Config.ARGB_8888, true);
    imageView.setImageBitmap(bitmap);
    imageView.invalidate();
}

So now the problem is, the lines are drawn under the image so that i cannot see it. I want the lines to be drawn over the image. How should i implement it?

2 Answers
Related