无法在Glide 4.4上使用滑行变换

sud*_*007 3 android image android-glide

我搜索了所有地方,但自从Glide发布4.4版以来。我再也找不到一种应用RoundedCornersTransformation的方法。我正在使用滑行变换,即使在他们的Github论坛上也没有正确的解决方案。

先前:

GlideApp.with(context)
.load(url)
.transforms(new CenterCrop(), new RoundedCorners(radius))
.into(imageView);
Run Code Online (Sandbox Code Playgroud)

然后必须通过更新来调用它,如下所示:

Glide.with(context)
   .load(url)
   .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(radius)))
   .into(imageView);
Run Code Online (Sandbox Code Playgroud)

但是使用Glide 4.4,我面临的问题是:

1:根本不应用转换。

2:如果我尝试使用.transformsAPI,似乎不再可用!

如果有人可以帮助,请回复。如果找到我的答复,我会发表!

sud*_*007 14

这是我在github上打开的项目中阅读的内容。

您可以使用Glide的RoundedCorners转换。并且请注意,centerCrop()会覆盖以前的转换。因此,您可以使用:

 Glide.with(context)
   .load(url)
   .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(radius)))
   .into(imageView);
Run Code Online (Sandbox Code Playgroud)

但不幸的是,格莱德(Glide)没有transforms(),只有transform()方法。

因此,我检查了我的代码,发现ImageView我在使用:

android:scaleType="centerCrop"
Run Code Online (Sandbox Code Playgroud)

结果,我的Transform被此属性覆盖,就像上面论坛中的评论中提到的那样。

centerCrop()覆盖以前的转换

最终解决方案:我scaleType="centerCrop"ImageViewxml布局中删除并这样编写代码。

RequestOptions options = new RequestOptions();
                options.placeholder(R.drawable.place_holder)
                        .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                        .error(R.drawable.error_place_holder)
                        .transform(new CenterCrop())
                        .transform(new RoundedCorners(corner_size));

                Glide.with(mActivity).load(url)
                        .apply(options)
                        .into(image_view);
Run Code Online (Sandbox Code Playgroud)

瞧!有效!

注意: centerCrop()对于不同的用例,可能会有所不同。


Dha*_*tha 5

根据 GitHub 中给出的描述https://github.com/bumptech/glide,使用它。

圆形图片:已知 CircleImageView/CircularImageView/RoundedImageView 在 TransitionDrawable(.crossFade() 与 .thumbnail() 或 .placeholder())和动画 GIF 方面存在问题,请使用 BitmapTransformation .circleCrop() 将在 v4 中提供)或.dontAnimate() 来解决该问题。

希望这有帮助。

编辑: 我已经尝试过你想要的,请看下面。使用https://github.com/bumptech/glidehttps://github.com/wasabeef/glide-transformations

MainActivity.java

package com.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

public class MainActivity extends AppCompatActivity {

ImageView imageView, imageView2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView = (ImageView) findViewById(R.id.imageView);
    imageView2 = (ImageView) findViewById(R.id.imageView2);


   Glide.with(this).load(R.mipmap.company_bg)
            .apply(RequestOptions.bitmapTransform(new CircleCrop()))
            .into(imageView);

   //this also works for Circle crop as above
     //Glide.with(this).load(R.mipmap.company_bg)
     //       .apply(RequestOptions.circleCropTransform())
     //       .into(imageView);


    Glide.with(this).load(R.mipmap.company_bg)
            .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(45, 0, RoundedCornersTransformation.CornerType.ALL)))
            .into(imageView2);

  }
}
Run Code Online (Sandbox Code Playgroud)

build.gradle文件中

 implementation 'com.github.bumptech.glide:glide:4.4.0'
 implementation 'jp.wasabeef:glide-transformations:3.0.1'
Run Code Online (Sandbox Code Playgroud)

这是图像的屏幕截图。 在此输入图像描述