Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - ImageView with rounded only one corner

I want to create ImageView like this (right side of the image):

enter image description here

I have it in CardView layout so I have rounded corners of the card but I need to create rounded left bottom corner of the image alone (or with top right).

I tried several options but nothing work correctly.

How can I do this? Do you have some tip?

like image 729
Pepa Zapletal Avatar asked Oct 16 '19 08:10

Pepa Zapletal


2 Answers

You can use the Material Components Library.
With the version 1.2.0-alpha03 there is the new ShapeableImageView.

Just use in your layout:

  <com.google.android.material.imageview.ShapeableImageView
      app:srcCompat="@drawable/..."
      ../>

And in your code apply the ShapeAppearanceModel with:

float radius = getResources().getDimension(R.dimen.default_corner_radius);
imageView.setShapeAppearanceModel(imageView.getShapeAppearanceModel()
    .toBuilder()
    .setTopRightCorner(CornerFamily.ROUNDED,radius)
    .setBottomLeftCorner(CornerFamily.ROUNDED,radius)
    .build());

enter image description here

like image 50
Gabriele Mariotti Avatar answered Sep 20 '22 01:09

Gabriele Mariotti


You can use this library and put your ImageView inside the Layout

https://github.com/JcMinarro/RoundKornerLayouts

and can set the radius for specific corners like this

containerLayout.setCornerRadius(2f, CornerType.ALL);
containerLayout.setCornerRadius(2f, CornerType.BOTTOM_LEFT);

Other choices

public final enum class CornerType private constructor() : kotlin.Enum<com.jcminarro.roundkornerlayout.CornerType> {
    ALL,

    TOP_LEFT,

    TOP_RIGHT,

    BOTTOM_RIGHT,

    BOTTOM_LEFT;
}
like image 45
Hamza Khan Avatar answered Sep 20 '22 01:09

Hamza Khan