Glide circular image gets cropped

家住魔仙堡 提交于 2019-12-24 17:28:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!