android - 在android中将颜色而不是图像设置为imageview
问题描述
我有ImageViews
显示客户图像的。如果客户的图像不可用,我想在 中显示灰色背景ImageView
。
编辑:它是来自 'de.hdodenhof:circleimageview:2.2.0' 的 CircleImageview 当我设置背景颜色时,它变成一个矩形而不是圆形。
解决方案
如果您使用的是 CircularImageView ,则可以创建一个圆形可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#808080"
/>
<size
android:height="120dp"
android:width="120dp"
/>
</shape>
然后在客户图像不可用时将其设置为资源。
推荐阅读
- swift - 如何从 string.index 中获取 Int?
- javafx - 为 TabPanes 选项卡使用 JavaFX PopOver 以查看其内容
- python-3.x - ipyparallel 推送一个元组以避免在每个引擎中加载它
- centos - 如何在 centos 7 上安装 Haxe
- c# - C# + VB:导入 reg 文件
- java - 由于响应中的错误结果,弹簧方法的 Mockito 测试失败
- c# - 如何删除一个sql数据行c#
- python - 在 python 中加载纽约大学深度 v2 数据集
- html - 相同的 HTML CSS 呈现不同,具体取决于单点登录
- bash - 从cygwin调用cmd / c时如何显示一行的彩色输出