I am new to android.
Can anyone help me with this problem.
I have a layout in which I have a imageView. What I want is I want to draw a rectangle on top of this image. The height of the rectangle is obtained during runtime.
I have tried drawing the rectangle by using shapeDrawable class and onDraw() method. But everytime I draw my layout disappears and what I get is a rectangle in a black background.
Can anyone please help me with this.
You can use a FrameLayout to overlap views. In your layout XML:
And then in
res/drawable/my_shape.xmlyou can have a Shape Drawable, for example:A second option is to use a custom view instead of the overlay view and override its
onDrawmethod to do customCanvasdrawing. In that case you would still use theFrameLayoutto position the view over your ImageView.A third option is to use a custom view and draw your image into it using
drawBitmapcalls in theonDrawmethod. This is probably the most flexible of the three methods.