Android : 如何创建像头像联系人一样的图像?

Android : How to create image like an avatar contact?

我想像下面这样创建 imageView(焦点在红色背景上)。

如果图片获取到的是空数据,那么imageView显示的文本会在空格后拆分

可以吗?

您可以使用 Picasso 或 Glide Image Loader 库,其中您可以使用占位符图像,当您的图像未加载或您的数据为空时,将显示占位符图像。

您可以根据需要使用 Adob​​e Illustrator 创建自定义图像并将其作为可绘制对象导入 Android Studio 并使用 Glide

将其用作占位符

代码示例

Glide.with(fragment)
  .load(url)
  .error(R.drawable.placeholder)
  .listener(new RequestListener<String, DrawableResource>() {
            public boolean onException(Exception e, String model, Target<DrawableResource> target, boolean isFirstResource) {
                // Hide ImageView and Display TextView
                return false;
            }

            public boolean onResourceReady(DrawableResource resource, String model, Target<DrawableResource> target, boolean isFromMemoryCache, boolean isFirstResource) {
                // Hide TextView and Display ImageView
                return false;
            }
        })
  .into(view);