【问题标题】:Set the listview item with different color if image is not available如果图像不可用,则将列表视图项设置为不同的颜色
【发布时间】:2018-05-24 05:19:10
【问题描述】:

我有一个listview,每个列表项中有一个imageview 和textview。
列表视图填充了 json 数据。
如果图像不是从json 传递的,现在我想设置不同的颜色
喜欢:

【问题讨论】:

  • 制作一个颜色数组,每次从数组中选择一个随机颜色。

标签: android colors listitem


【解决方案1】:

如果你正在使用滑翔,那么,

Glide.with(context).load(url).into(new SimpleTarget<GlideDrawable>() { @Override public void onResourceReady(GlideDrawable resource,GlideAnimation<? super GlideDrawable> glideAnimation) { } @Override public void onLoadFailed(Exception e, Drawable errorDrawable) { super.onLoadFailed(e, errorDrawable); Random rnd = new Random(); int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256),rnd.nextInt(256)); view.setBackgroundColor(color); } });

【讨论】:

    【解决方案2】:

    检查适配器中加载的数据是否为空。如果为空或“”,请为您的图像视图设置随机颜色。

    这可能对您有所帮助 Generate and set random colors on text view background within Recycler View in Android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-21
      • 2016-04-05
      相关资源
      最近更新 更多