错误:包com.bumptech.glide.request.animation不存在

时间:2018-08-22 06:38:45

标签: android android-glide

我在应用gradle中添加了以下软件包:

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:glide:4.8.0'

但是在运行时出现以下错误:

错误:包com.bumptech.glide.request.animation不存在

有人面对这样吗?

3 个答案:

答案 0 :(得分:2)

GladeAnimation已由Transition代替,所以现在代替

onResourceReady(GlideDrawable drawable, GlideAnimation<? super GlideDrawable> anim) 

您应该使用

onResourceReady(Drawable drawable, Transition<? super Drawable> transition);

您应该检查official site中所有不同的迁移更改。

干杯!

答案 1 :(得分:0)

对于您以前喜欢的版本3:

   private void setFeedImage(Uri imageUrl,File file) {
        BitmapImageViewTarget target = new BitmapImageViewTarget(feedImage) {

     @Override
            public void onResourceReady(final Bitmap bitmap,GlideAnimation anim) {
                super.onResourceReady(bitmap,anim);
                feedImage.setImageBitmap(bitmap);

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG,0,stream);
                byte[] bitmapBytes = stream.toByteArray();

                ParseFile image = new ParseFile("postImage",bitmapBytes);
                post.setPostImage(image);

            }

            @Override
            public void onLoadFailed(Exception e,Drawable errorDrawable) {
                super.onLoadFailed(e,errorDrawable);
                feedImage.setImageDrawable(errorDrawable);
            }

            @Override
            public void onLoadStarted(Drawable placeholder) {
                super.onLoadStarted(placeholder);
                feedImage.setImageDrawable(placeholder);
            }

但是对于第4版,您应该这样使用,而不是使用顶部代码:

  private void setFeedImage(Uri imageUrl,File file) {
            BitmapImageViewTarget target = new BitmapImageViewTarget(feedImage) {

                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    super.onResourceReady(resource, transition);

                    feedImage.setImageBitmap(resource);

                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    resource.compress(Bitmap.CompressFormat.PNG,0,stream);
                    byte[] bitmapBytes = stream.toByteArray();

                    ParseFile image = new ParseFile("postImage",bitmapBytes);
                    post.setPostImage(image);
                }

                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    super.onLoadFailed(errorDrawable);
                    feedImage.setImageDrawable(errorDrawable);
                }

                @Override
                public void onLoadStarted(@Nullable Drawable placeholder) {
                    super.onLoadStarted(placeholder);
                    feedImage.setImageDrawable(placeholder);
                }
            };

答案 2 :(得分:0)

使用以下方法更新您的gradle:

implementation 'com.github.bumptech.glide:glide:3.+'
annotationProcessor 'com.github.bumptech.glide:glide:4.8.0'