【问题标题】:Glide circular image gets croppedGlide 圆形图像被裁剪
【发布时间】:2018-05-29 23:24:55
【问题描述】:

我正在尝试使用滑行制作圆形图像视图... 我按照本教程 How to round an image with Glide library? 进行操作,但我的图像总是被顶部和底部裁剪

我试图改变图像视图的尺寸,但没有任何改变,总是被裁剪和相同的比例

我做错了什么

Glide.with(this).load(MasterFacade.getFacade().getLocalUser().getProfilePicUrl()).apply(RequestOptions.centerCropTransform()).into((ImageView) findViewById(R.id.profileImageView));

和布局

<ImageView
                android:id="@+id/profileImageView"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_gravity="center"
                android:scaleType="fitXY" />

【问题讨论】:

    标签: android imageview android-glide rounded-corners


    【解决方案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" />
    

    问题是与其他视图重叠,它应该可以解决您的问题

    【讨论】:

    • 它工作得很好,但你能解释一下那个边距是做什么的吗?为什么我需要它?以及你是如何获得 15 DP 的?
    • 边距只是在整个图像周围添加15dp的空间,就像与其他视图腾出空间一样,它有margin top,marginright,marginleft和marginbottom
    • 一个更好的方法应该是将该图像放在您的帖子关注和关注者视图上方以及工具栏下方,如果您在相对布局内有这个,您可以在上方和下方进行操作
    • 此解决方案几乎无济于事。
    【解决方案2】:
    Glide.with(context)
        .load("https://yourImageUrl.jpg")
        .apply(new RequestOptions().circleCrop())
        .into(headerImage);
    

    【讨论】:

    • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
    • 是的,当然@Mark_Rotteveel,感谢您的宝贵建议。
    【解决方案3】:

    试试这个

    添加xml布局:

             <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>
    

    添加 Java 代码使用 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();
                        }
                    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      • 2014-12-12
      • 2021-06-12
      • 2016-05-01
      • 2021-10-08
      相关资源
      最近更新 更多