To make a rounded corner layout or image there is plenty of ways and libraries for this
even you can use the CardView
attributes to create that
So what is the problem :D . what if you want to make the layout rounded in specific corner
or all corners expect one for example . actually there are familiar solution for this
to make a XML
file like this
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fff" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
and make it background to this layout and you are done. this solution will work for the most cases but what if you try to use Glide or Picasso to upload the image in imageView in that layout. the rounded corner is gone because the image override the background so know you have to solutions
1- To make a custom transformation and pass the image to it but this solution if your images are have different sizes the rounded corner won't be equal in each view.
2-You can make a custom view as wrapper around your views and give it the exactly corners you want to round . the only problem with that solutions that your memory will increase a little bit.
So that is the code for the custom view that I created you can customize it in other way depend on your use case. you can specify the corner radius for specific corner in xml and in runtime
1- Declare a styleable
in your attrs.xml
file and it's name match the view name
2- Decalre the custom view as the code snippet
3- Decalre your xml file
5- but the drawable file also as backgroud also
4- load the images into the view
This the result of snippet code
I hope that will be helpfully :D
canvas.clipPath(path, Region.Op.REPLACE);
crashes iftargetSdkVersion 28
.Also see https://stackoverflow.com/questions/50231950/what-is-the-best-alternative-to-canvas-cliprect-with-region-op-replace