compile 'com.squareup.picasso:picasso:2.5.2'
这是我下载的picasso的依赖,下载后在项目中使用
Picasso.with(context)
.load(R.drawable.user)
.centerCrop()
.resize(avatarSize, avatarSize)
.transform(new RoundedTransformation())
.into(holder.ivUserAvatar);
尽管我在 RoundedTransformation 上收到红色代码,显示无法解析符号“RoundedTransformation” 我不习惯使用 Picasso,所以我需要一些帮助
最佳答案
你的问题是你没有这个类。
你可以使用这个类再试一次。
class RoundedTransformation implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap,
BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
@Override
public String key() {
return "circle";
}
}
关于java - 无法解析符号 'Rounded Transformation',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49289954/