问题
I'm trying to make a circular imageview using glide... I followed this tutorial How to round an image with Glide library? but my image always get the top and bottom cropped
i tried to change imageview dimensions but nothing changes, always cropped and same ratio
what am i doing wrong
Glide.with(this).load(MasterFacade.getFacade().getLocalUser().getProfilePicUrl()).apply(RequestOptions.centerCropTransform()).into((ImageView) findViewById(R.id.profileImageView));
and the layout
<ImageView
android:id="@+id/profileImageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:scaleType="fitXY" />
回答1:
<ImageView
android:id="@+id/profileImageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_margin="15dp"
android:scaleType="fitXY" />
The problem is that is overlaping the other views, with a margin it should solve your problem
回答2:
Try This
Add xml layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1dp"
android:id="@+id/lay_profpic"
android:layout_gravity="center"
android:layout_margin="20dp"
android:background="@drawable/border_circle">
<ImageView
android:id="@+id/profile_picture"
android:scaleType="centerCrop"
android:layout_centerHorizontal="true"
android:src="@color/white"
android:layout_gravity="center"
android:layout_width="90"
android:layout_height="90dp" />
</RelativeLayout>
Add Java code use Glide
Glide.with(this)
.load(user.getProfilePicture())
.transform(new CircleTransform(this))
.into(new GlideDrawableImageViewTarget(ivProfilePicture) {
@Override
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
super.onResourceReady(drawable, anim);
ivProfilePicture.setImageDrawable(drawable);
ivProfilePicture.invalidate();
ivProfilePicture.requestLayout();
}
});
来源:https://stackoverflow.com/questions/50594330/glide-circular-image-gets-cropped