glid4 - 进入方法

时间:2018-03-21 06:15:50

标签: android android-glide

今天我正在尝试在我的Android应用程序中使用Glide4图像加载器,同时使用这个我面对的方法没有解决问题。我已经搜索了很多并找到了解决方案,我必须创建RequestOptions并使用如下:

private void loadImages() {
    RequestOptions requestOptions = new RequestOptions();
    requestOptions.placeholder(R.drawable.circle_diff);
    requestOptions.centerCrop();
    Glide.with(this)
            .load("http://localhost/ImageRepo/profile.jpg")
            .apply(requestOptions)
    .into(new BitmapImageViewTarget(mBinding.profilePic){
        @Override
        protected void setResource(Bitmap resource) {
            RoundedBitmapDrawable circularBitmapDrawable =
                    RoundedBitmapDrawableFactory.create(getResources(), resource);
            circularBitmapDrawable.setCircular(true);
            mBinding.profilePic.setImageDrawable(circularBitmapDrawable);
        }
    });

但是在 .into 方法中我遇到Cannot resolve method 'into(anonymous com.bumptech.glide.request.target.BitmapImageViewTarget)错误。什么事发生?

我的应用程序gradle依赖项:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation("com.github.bumptech.glide:glide:4.6.1") {
        exclude group: "com.android.support"
    }
    implementation "com.android.support:support-fragment:26.1.0"

    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}

1 个答案:

答案 0 :(得分:3)

尝试使用 requestOptions.circleCropTransform();

    RequestOptions requestOptions = new RequestOptions();                    
    requestOptions.placeholder(R.drawable.ic_launcher_background);           
    requestOptions.circleCropTransform();                                    
    requestOptions.transforms( new RoundedCorners(300));                     

     Glide.with(this)                                                        
          .load("https://i.stack.imgur.com/7CChZ.jpg?s=328&g=1")             
          .apply(requestOptions)                                             
          .into(imageView);        

输出

enter image description here