当前位置:网站首页>ShapeableImageView 的使用,告别shape、三方库
ShapeableImageView 的使用,告别shape、三方库
2022-08-02 18:55:00 【梦想改变生活】
属性介绍
style 属性:
| 属性名 | 描述 | 作用 |
|---|---|---|
| cornerFamily | 属性/样式 | -rounded: 圆角0 -cut: 切角1 |
| cornerSize | 弧度 | 弧度大小 |
| cornerSizeTopLeft | 左上角弧度大小 | |
| cornerSizeTopRight | 右上角弧度大小 | |
| cornerSizeBottomRight | 右下角弧度大小 | |
| cornerSizeBottomLeft | 左下角弧度大小 | |
| cornerFamilyTopLeft | 左上角样式(圆角或切角) | |
| cornerFamilyTopRight | 右上角样式(圆角或切角) | |
| cornerFamilyBottomRight | 右下角样式(圆角或切角) | |
| cornerFamilyBottomLeft | 左下角样式(圆角或切角) |
布局属性:
| 属性名 | 描述 | 作用 |
|---|---|---|
| shapeAppearance | shapeableImageView的形状外观样 | 引用style样式 |
| shapeAppearanceOverlay | ShapeableImageView的形状外观叠加样式 | 引用style样式 |
| strokeColor | 描边颜色 | |
| strokeWidth | 描边粗细 |
样式案例
build.gradle 配置
implementation 'com.google.android.material:material:1.6.1'

对应Style如下:
<!--圆形-->
<style name="roundStyle">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
<!--圆角-->
<style name="roundedCornerImageStyle10">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">10dp</item>
</style>
<!--切角-->
<style name="roundedCutStyle">
<item name="cornerFamily">cut</item>
<item name="cornerSize">10dp</item>
</style>
<!--左上右上圆角-->
<style name="roundedTopStyle">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopLeft">20dp</item>
<item name="cornerSizeTopRight">20dp</item>
</style>
<!--菱形-->
<style name="roundedDiamondStyle">
<item name="cornerFamily">cut</item>
<item name="cornerSize">50%</item>
</style>
<!--子弹头-->
<style name="roundedBulletStyle">
<item name="cornerFamilyTopRight">rounded</item>
<item name="cornerSizeTopRight">50dp</item>
<item name="cornerSizeTopLeft">50dp</item>
<item name="cornerFamilyTopLeft">rounded</item>
</style>
<!--Tips-->
<style name="roundedTipsStyle">
<item name="cornerFamilyTopLeft">rounded</item>
<item name="cornerSizeTopLeft">50%</item>
<item name="cornerFamilyBottomLeft">rounded</item>
<item name="cornerSizeBottomLeft">50%</item>
<item name="cornerFamilyTopRight">cut</item>
<item name="cornerSizeTopRight">50%</item>
<item name="cornerFamilyBottomRight">cut</item>
<item name="cornerSizeBottomRight">50%</item>
</style>
<!-- 左上角90度扇形图片 -->
<style name="topLeftRoundImageStyle">
<item name="cornerFamilyTopLeft">rounded</item>
<item name="cornerSizeTopLeft">100%</item>
</style>
有个小细节需要注意,当我们使用strokeWidth属性时,一定要对应设置padding,否则会出现显示一半的效果。而padding的值设置为strokeWidth值的一半。如:
app:strokeWidth="5dp"
android:padding="2.5dp"
代码已上传github:
https://github.com/ljlstudio/KtMvvm/tree/master/demo/src/main/java/com/kt/ktmvvm/jetpack/shapeableimageview
边栏推荐
- From the technical panorama to the actual scene, analyze the evolutionary breakthrough of "narrowband high-definition"
- 【C语言刷题】Leetcode203——移除链表元素
- 元宇宙001 | 情绪无法自控?元宇宙助你一臂之力
- 【学习日记】win64配置openni的vs2022编译环境
- 新公链时代的跨链安全性解决方案
- 药品研发--工艺技术人员积分和职务考核评估管理办法
- 简单有效又有用的关闭antimalware service executable的方法·备份记录
- 基于OpenGL的冰川与火鸟(光照计算模型、视景体、粒子系统)
- 流量分析三—远程登陆
- 深度学习-学习笔记(持续更新)
猜你喜欢
随机推荐
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
7.21 - 每日一题 - 408
进程与线程
Therapy | How to Identify and Deal with Negative Thoughts
香农与信息论三大定律
golang刷leetcode 数学(1) 丑数系列
Geoserver+mysql+openlayers2
Detailed explanation of AtomicInteger
Boyun Selected as Gartner China DevOps Representative Vendor
中职网络安全竞赛之应用服务漏洞扫描与利用
Monitor is easy to Mars debut: distributed operations help TOP3000 across management gap
golang刷leetcode 经典(12) 完全二叉树插入器
golang面试题
平稳发展 | 西欧地区手游玩家的数据和洞察
Gradle系列——Gradle的build.gradle文件详情,项目发布(基于Gradle文档7.5)day3-3
Geoserver+mysql+openlayers
Metaverse 001 | Can't control your emotions?The Metaverse is here to help you
[Dynamic Programming Special Training] Basics
视频隐写一
治疗 | 如何识别和处理消极想法









