圆
<com.google.android.material.imageview.ShapeableImageView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_margin=“10dp”
android:src=“@mipmap/ic_avatar”
app:shapeAppearance=“@style/CircleStyle” />
- 圆角的大小可以用百分比,也可以自己计算,比如宽高100dp,圆角50dp
描边
<com.google.android.material.imageview.ShapeableImageView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_margin=“10dp”
android:padding=“2dp”
android:src=“@mipmap/ic_avatar”
app:shapeAppearance=“@style/CircleStyle”
app:strokeColor=“@color/red”
app:strokeWidth=“4dp” />
-
app:strokeColor 描边颜色
-
app:strokeWidth 描边宽度
-
注意这里padding的数值是描边宽度的一半,后面会说
切角
<com.google.android.material.imageview.ShapeableImageView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_margin=“10dp”
android:padding=“2dp”
android:src=“@mipmap/ic_avatar”
app:shapeAppearance=“@style/CutStyle”
app:strokeColor=“@color/red”
app:strokeWidth=“4dp” />
- cornerFamily:cut 处理模式变为裁剪
菱形
<com.google.android.material.imageview.ShapeableImageView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_margin=“10dp”
android:padding=“2dp”
android:src=“@mipmap/ic_avatar”
app:shapeAppearance=“@style/RhombusStyle”
app:strokeColor=“@color/red”
app:strokeWidth=“4dp” />
- 同样,裁剪模式下圆角大小也可以计算
叶子
<com.google.android.material.imageview.ShapeableImageView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_margin=“10dp”
android:padding=“2dp”
android:src=“@mipmap/ic_avatar”
app:shapeAppearance=“@style/LeafStyle”
app:strokeColor=“@color/red”
app:strokeWidth=“4dp” />
-
cornerSizeTopLeft 左上圆角
-
cornerSizeBottomR