Reputation: 9
I am using hdodenhof.circleimageview lib,
I am getting image like this - image here
How can i fit the image into this, without stretching image outside
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/layout_edit_category"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:contextClickable="true"
android:clickable="true"
android:layout_margin="4dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/edit_category_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:src="@drawable/transport"
android:padding="8dp"
android:cropToPadding="true"
android:elevation="8dp"
app:civ_border_width="1dp"
app:civ_border_overlay="true"
android:clickable="true"
app:civ_circle_background_color="@color/colorLightGrey"
app:civ_border_color="@color/colorGrey"
/>
<TextView
android:id="@+id/edit_category_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Text"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:layout_below="@id/edit_category_image"
android:maxLines="1"
android:maxLength="16"
android:ellipsize="end"
/>
</RelativeLayout>
Is it possible to decrease size or something
Upvotes: 0
Views: 936
Reputation: 543
option 1
val imageLoader: ImageLoader = ImageLoader.getInstance()
val options: DisplayImageOptions = DisplayImageOptions
.Builder()
.displayer(CircleBitmapDisplayer())
.showImageOnLoading(drawable)
.showImageOnFail(drawable)
.showImageForEmptyUri(drawable)
.cacheInMemory(true)
.cacheOnDisk(true)
.build()
imageLoader.displayImage(imageUrl, imageView, options)
option 2
Glide.with(context)
.load(imageUrl)
.apply(RequestOptions.circleCropTransform())
.into(imageView)
You can try this with Imageview by setting scaltype in xml without using circle imageview
Upvotes: 2
Reputation: 258
try with this
Picasso.with(context).load(url).noFade().transform(CircleTransform()).into(imageView)
public class CircleTransform implements Transformation {
public CircleTransform() { }
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 7;
int y = (source.getHeight() - size) / 7;
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";
}
}
Upvotes: 0
Reputation: 577
Add some padding to the image or use an image with 1:1 aspect ratio. This library doesn't support scaleType so you can do it without any 3rd Party library
<androidx.cardview.widget.CardView
android:layout_width="75dp"
android:layout_height="75dp"
app:cardCornerRadius="50dp"
app:strokeWidth="1dp"
app:strokeColor="@color/black">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/circular_image"
android:scaleType="fitCenter"
android:src="@drawable/your_img" />
</androidx.cardview.widget.CardView>
Upvotes: 0