背景黑色在圆形ImageView中显示

3

我设计了一个CircularImageView,但当我运行应用程序时,在我的布局中,圆形图像周围出现黑色背景问题,该如何解决这个问题。

XML文件

<de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/gs_image_userProfileimage"
            android:layout_width="80dp"
            android:layout_height="80dp"
            app:civ_border_color="#95c764"
            app:civ_border_width="2dp"

            app:civ_shadow_radius="3" />

Java编码:

 gs_image_userProfileimage=(ImageView)view.findViewById(R.id.gs_image_userProfileimage);

     Picasso.with(getContext())
      .load(gs_var_userimage)
      .placeholder(R.drawable.getspot_logo)
       .into(gs_image_userProfileimage);

尝试使用setLayout(view.Layout_Hardware),但仍然显示相同的内容。


你能贴一下屏幕截图吗? - Vir Rajpurohit
我添加了屏幕截图。 - Kalaivani R
发布完整的XML。 - V-rund Puro-hit
你是否尝试过使用Glide而不是Picasso? - Vir Rajpurohit
如果我第一次使用Glide时,它在我进入某些菜单时无法加载,但是当我返回时它就可以工作了。为什么第一次不能加载? - Kalaivani R
4个回答

2
您可以简单地设置圆环的背景颜色。
app:civ_circle_background_color="@color/blue_background"

虽然它没有解决我的问题,但是你的答案给了我解决问题的线索。谢谢。 - Abdul Waheed

1

尝试将ImageView类型更改为CircleImageView

声明应为

de.hdodenhof.circleimageview.CircleImageView gs_image_userProfileimage;

然后像这样使用

gs_image_userProfileimage=(de.hdodenhof.circleimageview.CircleImageView)view.findViewById(R.id.gs_image_userProfileimage);
gs_image_userProfileimage.setLayerType(View.LAYER_TYPE_HARDWARE, null);

如果是Lollipop版本,请尝试使用以下代码:gs_image_userProfileimage.setLayerType(View.LAYER_TYPE_HARDWARE, null);。请查看更新后的答案。 - Navneet Krishna
是的,但我不知道为什么它仍然显示问题,是Picasso出了问题吗?如果我使用Glide图片,第一次不会显示。 - Kalaivani R
不可能是因为 Picasso,你尝试过所有三种 LAYER_TYPE_HARDWARELAYER_TYPE_NONELAYER_TYPE_SOFTWARE 吗? - Navneet Krishna
如果仍然无法工作,请尝试将“CircleImageView”包装在LinearLayout中,并将“setLayerType”分配给LinearLayout。 - Navneet Krishna
LinearLayout laylinear=(LinearLayout)view.findViewById(R.id.laylinear); laylinear.setLayerType(View.LAYER_TYPE_HARDWARE, null); laylinear.setLayerType(View.LAYER_TYPE_SOFTWARE, null); laylinear.setLayerType(View.LAYER_TYPE_NONE, null);对吧?同样的问题。 - Kalaivani R

1

像下面的代码一样定义您的图像视图背景...

    <de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/gs_image_userProfileimage"
    android:layout_width="80dp"
    android:layout_height="80dp"
    app:civ_border_color="#95c764"
    app:civ_border_width="2dp"
    android:background="@color/white"
    app:civ_shadow_radius="3" />

只更改这个

    android:background="@color/white"

0
如果您在圆形图像后面有一个视图或布局小部件,则必须将Tint设置为透明,如下所示:
<de.hdodenhof.circleimageview.CircleImageView
     android:id="@+id/gs_image_userProfileimage"
     android:layout_width="80dp"
     android:layout_height="80dp"
     app:civ_border_color="#95c764"
     app:civ_border_width="2dp"
     android:backgroundTint="@android:color/transparent"
     app:civ_shadow_radius="3" />

示例: {{link1:问题}}

Fixed


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接