ShapeableImageView 設置圓角
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/ivImg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
then
使用 kotlin 的 extend
fun ShapeableImageView.setRadius(@DimenRes source: Int) {
val radius = context.getDimenFloat(source)
val newShapeAppearanceModel = shapeAppearanceModel.toBuilder()
.setAllCornerSizes(radius)
.build()
shapeAppearanceModel = newShapeAppearanceModel
}
就很方便的根據每次的需求去改變 radius 惹~
參考
ShapeableImageView – Material components for android [Example]
android:id="@+id/ivImg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
then
使用 kotlin 的 extend
fun ShapeableImageView.setRadius(@DimenRes source: Int) {
val radius = context.getDimenFloat(source)
val newShapeAppearanceModel = shapeAppearanceModel.toBuilder()
.setAllCornerSizes(radius)
.build()
shapeAppearanceModel = newShapeAppearanceModel
}
就很方便的根據每次的需求去改變 radius 惹~
參考
ShapeableImageView – Material components for android [Example]