如何使用Glide将svg图像加载到图像视图



我在这个URL中有一个SVG图像。svg图像链接。我想将此SVG图像从url加载到image view中。我已使用Glide将此SVG映像加载到image view

这是滑翔代码:

Glide.with( context)
.setDefaultRequestOptions(new RequestOptions().timeout(60000))
.load( "https://restcountries.eu/data/zwe.svg" )
.thumbnail( 0.5f )
.override( 200, 200 )
.diskCacheStrategy( DiskCacheStrategy.ALL )
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
progressLayout.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressLayout.setVisibility(View.GONE);
flag_iv.setEnabled(true);
return false;
}
})
.into( flag_iv );

XML代码:

<ImageView
android:src="@drawable/icon_app"
android:id="@+id/flag_iv"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
/>

但它没有加载。它显示以下错误。

W/Glide: Load failed for https://restcountries.eu/data/afg.svg with size [100x100]

我已经使用Glide使用了png/jpg图像。效果很好。为什么不使用Glide加载SVG图像。我搜索了Stack Overflow。每个人都在建议不同的图书馆。但它们已经过时了。我想用Glide来实现它。请帮我解决一些问题。

您可以使用Glide To Vector,

回购:https://github.com/corouteam/GlideToVectorYou

要将svg加载到imageview中,您可以使用:

GlideToVectorYou
.init()
.with(this)
.withListener(new GlideToVectorYouListener() {
@Override
public void onLoadFailed() {
Toast.makeText(context, "Load failed", Toast.LENGTH_SHORT).show()
}
@Override
public void onResourceReady() {
Toast.makeText(context, "Image ready", Toast.LENGTH_SHORT).show()
}
})
.setPlaceHolder(placeholderLoading, placeholderError)
.load(IMAGE_URL, imageview);

最新更新