12

I have a ShapeableImageView here, with 5dp stroke:

<com.google.android.material.imageview.ShapeableImageView
    android:id="@+id/profile_picture"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginTop="20dp"
    android:scaleType="centerCrop"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/profile_toolbar"
    app:shapeAppearanceOverlay="@style/circular"
    app:strokeColor="@color/dark_blue"
    app:strokeWidth="5dp" />

This is the result:

here is the result

hata
  • 11,633
  • 6
  • 46
  • 69

4 Answers4

15

i've been trying some stuff, and finally, adding a padding to the view fixed the problem

  • 3
    One thing to mention on the `ShapeableImageView` is that it has two padding options. 1- `app:contentPadding` set is for padding its content like images we use. 2- `android:padding` set is for padding imageview itself. So what makes it work here is the `android:padding`. – Kozmotronik Aug 24 '22 at 07:52
2

only you need to give it padding may be 5dp will be suitable ( more or less )

Noah Mohamed
  • 114
  • 1
  • 1
  • 8
2

if your are giving stroke width then you must provide padding equal to stroke width too so that stroke must be visible

            android:strokeWidth="5dp"
            android:padding="5dp"
-1

I don't think ShapeableImageView is supposed to use to draw border stroke. I think it is supposed to just clip its image resource to the specified shape.

<com.google.android.material.imageview.ShapeableImageView
    android:id="@+id/profile_picture"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginTop="20dp"
    android:background="#FF0000"
    android:scaleType="centerCrop"
    android:src="@drawable/ic_launcher_foreground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:shapeAppearanceOverlay="@style/circular" />

screenshot

hata
  • 11,633
  • 6
  • 46
  • 69