You can use ShapeableImageView
for this, which is provided in the material
components package. If you are already using material theme in your project, then you are good to go, otherwise, add material
dependency.
implementation 'com.google.android.material:material:1.4.0'
And inherit, you AppTheme
from MaterialComponents
, in styles.xml
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
...
...
</style>
Add a new style to style.xml
for creating the rounded corner of the image.
<style name="ShapeAppearanceOverlay.RoundedCorner" parent="">
<item name="cornerSizeTopRight">75dp</item>
<item name="cornerFamilyTopRight">rounded</item>
<item name="cornerSizeBottomLeft">75dp</item>
<item name="cornerFamilyBottomLeft">rounded</item>
</style>
Change your ImageView
to a ShapeableImageView
in layout, and add above ShapeAppearnaceOverlay
style to it, using app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.RoundedCorner"
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="250dp"
android:layout_height="350dp"
android:src="@drawable/pots"
android:scaleType="centerCrop"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.RoundedCorner"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/toEncrypt"
app:layout_constraintBottom_toTopOf="@id/decrypted"
android:id="@+id/encrypted" />
Note - Use android:scaleType="centerCrop"
, so you don't get a clipping effet on either side of the image.
Result -
