【Android -- Material Design】ShapeableImageView 的基本使用

前言

官网:ShapeableImageView
013.png

属性

属性含义
strokeWidth描边宽度
strokeColor描边颜色
shapeAppearance外观样式
shapeAppearanceOverlay同上,叠加层

使用

  1. 引入 material 包:
implementation 'com.google.android.material:material:1.2.1'
  1. 普通
    01.png
<com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/shapeableImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:src="@mipmap/ic_avatar" />
  1. 圆角
    02.png
<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/RoundedStyle" />

--------------------------------style.xml-----------------------------------------
<!-- 圆角-->
    <style name="RoundedStyle">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">10dp</item>
    </style>
  1. 圆形
    02.png
<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" />

--------------------------------style.xml-----------------------------------------
<!-- 圆 -->
    <style name="CircleStyle">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">50%</item>
    </style>
  1. 圆形描边
    04.png
<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"
        app:strokeColor="@color/black"
        app:strokeWidth="4dp" />

--------------------------------style.xml-----------------------------------------
<!-- 圆 -->
    <style name="CircleStyle">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">50%</item>
    </style>
  1. 切角
    05.png
<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/black"
        app:strokeWidth="4dp" />

--------------------------------style.xml-----------------------------------------
<!-- 切角 -->
    <style name="CutStyle">
        <item name="cornerFamily">cut</item>
        <item name="cornerSize">10dp</item>
    </style>
  1. 菱形
    06.png
<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/RhombusStyle"
    app:strokeColor="@color/black"
    app:strokeWidth="4dp" />

--------------------------------style.xml-----------------------------------------
<!-- 菱形 -->
<style name="RhombusStyle">
    <item name="cornerFamily">cut</item>
    <item name="cornerSize">50%</item>
</style>
  1. 叶子
    07.png
<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/LeafStyle"
    app:strokeColor="@color/black"
    app:strokeWidth="4dp" />

--------------------------------style.xml-----------------------------------------
<!-- 叶子 -->
<style name="LeafStyle">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSizeTopLeft">50%</item>
    <item name="cornerSizeBottomRight">50%</item>
</style>
  1. 半圆
    08.png
<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/SemicircleStyle"
    app:strokeColor="@color/black"
    app:strokeWidth="4dp" />

--------------------------------style.xml-----------------------------------------
<!-- 半圆 -->
<style name="SemicircleStyle">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSizeTopLeft">50%</item>
    <item name="cornerSizeTopRight">50%</item>
</style>

关注我的视频号,每天都有优质视频教学推送。

微信扫一扫下方二维码即可关注:
在这里插入图片描述

  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kevin-Dev

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值