Hello. Created a custom view. It draws rectangles rect. It is necessary to round off the lower left corner. custom view The figure is marked in red what needs to be done. How can I make such a rounding?

    2 answers 2

    Here is my method that draws a rectangle with rounded upper and lower right corners, you need to remove the rounding of the upper one and it will work as it should.

    /** Path в поле, чтобы не было инициализации в onDraw(). */ private final Path eventPath = new Path(); /** Радиус закругления. */ private int eventRadius = 3; private void drawRoundRect(float left, float top, float right, float bottom, Paint paint, Canvas canvas) { eventPath.moveTo(left, top); eventPath.lineTo(right, top); eventPath.lineTo(right, bottom); eventPath.lineTo(left + eventRadius, bottom); eventPath.quadTo(left, bottom, left, bottom - eventRadius); eventPath.lineTo(left, top + eventRadius); eventPath.quadTo(left, top, left + eventRadius, top); canvas.drawPath(eventPath, paint); eventPath.reset(); } 
    • Something seems to me that your code will not work. Let me take off my view and you will look. I just have everything through rect - Ivan
    • and what's the difference if drawn on Canvas ? Throw off. - georgehardcore
    • Do you own the last rectangle rounds? - Ivan
    • where does the rectangle? - georgehardcore
    • I am doing an epg. So in the figure these are rectangles drawrect - Ivan

    Cardview should be used in the CardView :

     <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" app:cardCornerRadius="10dp" > <!-- blah-blah--> </android.support.v7.widget.CardView> 

    The radius of the corner is set by the app:cardCornerRadius attribute app:cardCornerRadius

    • It's not that anyway. If I place my view in CardView, my obtuse angles go beyond the rounded CardViewIvan
    • Show Your View - Barmaley
    • If you draw programmatically (and judging by the chat it is), then naturally it will not work like that. I advise you not to engage in antipattern, but to draw the layout as it should be in XML - then everything will be ok. CardView itself will act as a rectangle - Barmaley