如何在Android中使用RoundedImageView for Picasso

时间:2014-09-08 12:48:38

标签: java android maven

我想从RoundedImageView中的Picasso库加载图像

我从https://github.com/vinc3m1/RoundedImageView

采取参考

我真的无法理解如何使用RoundedImageView

你能告诉我如何使用..我无法理解......如何使用

当我设置布局

<com.makeramen.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="centerCrop"
        app:corner_radius="30dip"
        app:border_width="2dip"
        app:border_color="#333333"
        app:mutate_background="true"
        app:oval="true" />

代替ImageView ...给出错误......

我从这里下载了tornImageview的Java.doc.jar http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.makeramen%22%20AND%20a%3A%22roundedimageview%22

并添加到libs文件夹和构建路径

添加后...没有找到资源

更新

//tv_gender.setText(Gender);
          iv = (ImageView)rootView.findViewById(R.id.imageView1);
        tv_intrseted.setText(IntrestedIn);
    //  Button logout=(Button)rootView.findViewById(R.id.logout);
        RoundedImageView iv = new RoundedImageView(context);
        iv.setScaleType(ScaleType.CENTER_CROP);
        iv.setCornerRadius(10);
        iv.setBorderWidth(2);
        iv.setBorderColor(Color.DKGRAY);
        iv.setMutateBackground(true);
        iv.setImageDrawable(drawable);
        iv.setBackground(backgroundDrawable);
        iv.setOval(true);

如果我使用Like This给出错误..无法解析RoundedImageView

4 个答案:

答案 0 :(得分:1)

尝试使用可用的库尝试使用 https://github.com/Pkmmte/CircularImageView

对于android.First中的圆形ImageView尝试创建一个基本的。Androidgreeve在这里我发现了一篇关于创建roundImageview的文章,如facebook messanger

答案 1 :(得分:0)

This is the procedure, what i followed for one of my project. Please, have a look. It may lead you to find the solution as per your requirement.

Create a class `RoundedTransform` and paste this code.

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.squareup.picasso.Transformation;

public class RoundedTransform 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";
}
}


Then while calling the image view in your Activity,call as follows 

        iv = (ImageView)rootView.findViewById(R.id.imageView1);
        String imageUrl = "image";
        String url = "Pass your url";   
            if(url!=null){                              
                imageUrl = url;
            }

            Picasso.with(getApplicationContext()).load(imageUrl).fit().centerCrop().transform(new RoundedTransform()).placeholder(R.drawable.ic_launcher).error(R.drawable.ic_launcher).into((ImageView)findViewById(R.id.imageView1));

答案 2 :(得分:0)

改造毕加索。

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

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

答案 3 :(得分:0)

将它们编辑为:

app:riv_corner_radius="30dip"

app:riv_border_width="2dip"

有关详细信息,请参阅this