Today I just tried out ShapeableImageView
from Material design,
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/GuidelineTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.15" />
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/imgProfile"
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="centerCrop"
app:strokeColor="@color/grey400"
app:strokeWidth="@dimen/dp3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:adjustViewBounds="true"
app:layout_constraintTop_toBottomOf="@+id/GuidelineTop"
app:shapeAppearanceOverlay="@style/circleImageView" />
</androidx.constraintlayout.widget.ConstraintLayout>
And my circleImageView
<style name="circleImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
Here is the sample screenshot.
As you see, stroke is cut-off on left, top, right, bottom. Is there anything I missed?
As stroke in android Paint
is always drawn centered (half inside, half outside), you can add paddings as wide as half of the stroke width.
<com.google.android.material.imageview.ShapeableImageView
...
app:strokeWidth="@dimen/dp3"
android:padding="@dimen/dp4"
/>
(where dp4
is considered to be half of dp3
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With