The Material Components Library introduced with the 1.2.0-alpha03
the new ShapeableImageView
.
In your layout you can use:
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view"
app:srcCompat="@drawable/..." />
Then in your code apply the ShapeAppearanceModel
to define your custom corners:
@ExperimentalImageView
private void setup() {
ShapeableImageView imageView = findViewById(R.id.image_view);
float radius = getResources().getDimension(R.dimen.default_corner_radius);
imageView.setShapeAppearanceModel(imageView.getShapeAppearanceModel()
.toBuilder()
.setTopRightCorner(CornerFamily.ROUNDED,radius)
.build());
}
Also you can use the shapeAppearanceOverlay attribute in your layout to define the shape with a style.
For example to achieve a circular image:
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image_view"
app:shapeAppearanceOverlay="@style/circleImageView"
app:srcCompat="@drawable/..." />
with:
<style name="circleImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
I removed the background attribute but still Iam getting the same result. Also changed the parent layout from framelayout to relative layout but no success. Iam sharing you my Themes.xml file if it could be helpul