Android 和 roundedimageview:如何改变边框颜色

Android and roundedimageview: how to change the border color

在我的 XML 布局中,我使用此代码为图像视图创建特定形状:

 <com.makeramen.roundedimageview.RoundedImageView
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/avatar"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:src="@drawable/adduserprofile"
                android:scaleType="centerCrop"
                app:riv_border_width="5dip"
                app:riv_border_color="#ff9800"
                app:riv_mutate_background="true"
                app:riv_oval="false"
                app:riv_corner_radius_bottom_right="15dp"
                app:riv_corner_radius_top_left="15dp"
                app:riv_corner_radius_bottom_left="15dp"
                />

然后我用 Picasso 以这种方式加载图像:

Picasso.get().load(url.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).networkPolicy(NetworkPolicy.NO_CACHE).into(p_avatar);

是否可以使用 Picasso 或任何其他方法更改 Java 中的边框颜色? 我想根据某些用户的事件更改边框颜色。

谢谢!

您可以使用 Transformation 对象来设置形状的属性。对不同的事件使用不同的转换对象。

Transformation transformation = new RoundedTransformationBuilder()
      .borderColor(Color.BLACK)
      .borderWidthDp(3)
      .cornerRadiusDp(30)
      .oval(false)
      .build();

Picasso.with(context)
.load(url)
.fit()
.transform(transformation)
.into(imageView);

您应该在使用前检查 README 库。

试一试。

((RoundedImageView) view.findViewById(R.id.avatar)).setBorderColor(getResources().getColor(android.R.color.black));
((RoundedImageView) view.findViewById(R.id.avatar)).setBorderWidth(position * 5);
((RoundedImageView) view.findViewById(R.id.avatar)).setCornerRadius(position * 5);
((RoundedImageView) view.findViewById(R.id.avatar)).setImageBitmap(item.mBitmap);
((RoundedImageView) view.findViewById(R.id.avatar)).setScaleType(item.mScaleType);