how to draw empty rectangle with etc. borderWidth=3 and borderColor=black and part within rectangle don't have content or color. Which function in Canvas to use
void drawRect(float left, float top, float right, float bottom, Paint paint)
void drawRect(RectF rect, Paint paint)
void drawRect(Rect r, Paint paint)
Thanks.
I try this example
Paint myPaint = new Paint();
myPaint.setColor(Color.rgb(0, 0, 0));
myPaint.setStrokeWidth(10);
c.drawRect(100, 100, 200, 200, myPaint);
It draws rectangle and fill it with black color but I want just "frame" around like this image:
and either one of your
drawRect
should work.The code is fine just setStyle of paint as STROKE
Don't know if this is too late, but the way I solved this was to draw four thin rectangles that together made up a one big border. Drawing the border with one rectangle seems to be undoable since they're all opaque, so you should draw each edge of the border separately.
Create a new class
MyView, Which extends View
. Override theonDraw(Canvas canvas)
method to draw rectangle onCanvas
.Then Move your Java activity to
setContentView()
using our custom View, MyView.Call this way.For more details you can visit here
Assuming that "part within rectangle don't have content color" means that you want different fills within the rectangle; you need to draw a rectangle within your rectangle then with stroke width 0 and the desired fill colour(s).
For example:
DrawView.java
The activity to start it:
StartDraw.java
...will turn out this way: