Java 如何在android中使用毕加索的RoundeMageView
我想在RoundeImage视图中加载毕加索库中的图像Java 如何在android中使用毕加索的RoundeMageView,java,android,maven,Java,Android,Maven,我想在RoundeImage视图中加载毕加索库中的图像 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.graph
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));
我在引用
我真的无法理解如何使用RoundeMageView
你能告诉我怎么用吗我不懂怎么用
当我设置布局时
<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" />
如果我使用这样的给定错误..无法解决RoundeMageView尝试使用可用的库尝试使用
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));
对于android中的圆形图像视图,首先尝试创建一个基本视图。在这里,我找到了一篇关于在facebook messanger中创建roundImageview的文章,为毕加索做了一个转变
Transformation transformation = new RoundedTransformationBuilder()
.borderColor(Color.BLACK)
.borderWidthDp(3)
.cornerRadiusDp(30)
.oval(false)
.build();
Picasso.with(context)
.load(url)
.fit()
.transform(transformation)
.into(imageView);
将其编辑为:
app:riv_corner_radius="30dip"
app:riv_border_width="2dip"
有关更多信息,请参阅。@Prag'sシ 我发布了我的布局部分…我用它代替ImageView givign错误找不到资源…您的java代码亲爱的..更新了..@Prag'sシ 这是另一个供您尝试和实施的方法