我尝试在图像视图中显示一个GIF图像作为加载占位符 – 使用Glide库 :
Glide.with(context) .load(ImageUrl()) .placeholder(R.drawable.loading2) .asGif() .crossFade() .into(image);
我试图展示这个文件
loading2.gif
但得到这个错误:
错误:(54,86)错误:无法find符号方法asGif()
我怎样才能显示GIF文件与glide在imageView?
上面的答案对我没有用。 下面的代码工作。
ImageView imageView = (ImageView) findViewById(R.id.imageView); GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView); Glide.with(this).load(R.raw.sample_gif).into(imageViewTarget);
对于Glide 3.0,你需要先设置asGif():
Glide.with(context) .load(imageUrl) .asGif() .placeholder(R.drawable.loading2) .crossFade() .into(imageView);
请记住,只要使用load()
将根据数据的types加载GIF或位图。 除非你想让你的载入失败,如果给定的url不是一个gif,你不需要指定asGif()
从Glide 4.0.0-RC0开始
ImageView imageView = (ImageView) findViewById(R.id.imageView); Glide.with(this).load(R.raw.image_gif).asGif().into(imageView);
我有这个相同的问题。 你可以通过移动asGif()
所在的asGif()
来解决它。 它必须直接.load()
之前。
所以改变:
Glide.with(context) .load(ImageUrl()) .placeholder(R.drawable.loading2) .asGif() ....
至
Glide.with(context) .asGif() .load(ImageUrl()) .placeholder(R.drawable.loading2) ....
尝试这个。 它为我工作,并会为您的代码也工作。它既适用于图像也适用于gif。
ImageView imageView = (ImageView) findViewById(R.id.test_image); GlideDrawableImageViewTarget imagePreview = new GlideDrawableImageViewTarget(imageView); Glide .with(this) .load(url) .listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { return false; } }) .into(imagePreview); }
这个解决scheme是一种解决方法
<RelativeLayout android:layout_width="wrap_content" android:id="@+id/ImageContainer" android:background="#fff" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:id="@+id/loadingImageView" android:layout_centerInParent="true" android:layout_height="wrap_content"/> <ImageView android:id="@+id/mainImageView" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:layout_centerInParent="true" /> </RelativeLayout>
这是最好的方法
Glide.with(a).load(item[position]) .thumbnail(Glide.with(a).load(R.drawable.preloader)) .fitCenter() .crossFade() .into(imageView);
Glide.with(this) .load(R.drawable.logo) .asGif() .placeholder(R.drawable.logo) .into(imageView);
以上就是android开发分享用Glide显示GIF文件(图片加载和caching库)相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/addevelopment/518469.html