android material 组件 - ShapeableImageView

android:padding=“1dp”

android:scaleType=“centerCrop”

android:src=“@mipmap/ic_img”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent”

app:shapeAppearanceOverlay=“@style/ShapeAppearanceOverlay.MaterialComponents.FloatingActionButton”

app:strokeColor=“#ff0000”

app:strokeWidth=“2dp” />

app:strokeColorapp:strokeWidth 很好理解,分别是边框颜色和边框宽度

1 app:shapeAppearanceOverlay 这个呢就是圆角或者切角的关键属性了,

演示的代码使用的是material库中自带的style,如下:

大家可以按照需求自定义style以达到目的

注意:关于描边宽度需要注意的是,和自定义View一样,描边的宽度是中心点在Layout边界,所以是Layout边界内外均分strokeWidth的,所以描边是可能超出Layout边界的,造成截断的效果,所以可以设置内padding来处理溢出。

也就是说如果需求边框宽度为2dp那么需要设置android:padding="1dp" 以此类推,padding值为stokeWith值得一半

你可能感兴趣的:(android,gitee)