我是ImageView,Picasso,Glide的新手。我想从网址加载图片,我试过Glide和Picasso。他们两个加载图像很好,但如果我尝试从youtube(缩略图)加载图像 - 不加载。 // http://i.ytimg.com/vi/z0NfI2NeDHI/sddefault.jpg - 没有加载
main activity.Java
imageView = findViewById(R.id.image);
videoImg = ""
fetchData.execute(); //returns link for image to videoImg
Glide.with(this)
.load(videoImg)
.placeholder(R.drawable.ic_launcher_background)
.error(R.drawable.ic_launcher_foreground)
.into(imageView);
Picasso.get().load(videoImg).into(imageView);
activity_main.xml中
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
logcat的
W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
W/Glide: Load failed for null with size [0x0]
class com.bumptech.glide.load.engine.GlideException: Received null model
我认为你所面临的问题与Glide,Picasso或其他类似的图书馆无关。我尝试使用你使用Glide
提供的图像链接,它按预期工作。
我有根据的猜测是,您的设备正在使用某种受限制的网络,因此它会阻止来自/管道端点的请求。如果你从另一个网络连接它将工作得很好。
如果您只是想将图像加载到ImageView中,只需使用一个库,那么就说Glide。
不要忘记将maven Central()添加到buildscript下项目文件中的存储库
<uses-permission android:name="android.permission.INTERNET"/>
嗯,尴尬的情况..我使用自定义AsyncTask返回String(链接到yt图像)(在我的情况下是videoImg)所以我的代码是:
void ShowImage(View v){
fetchData.execute();
Glide.with(MainActivity.this)
.load(videoImg)
.placeholder(R.drawable.ic_launcher_background)
.error(R.drawable.ic_launcher_foreground)
.into(imageView);
}
所以AsyncTask没有时间下载链接和Glide只是试图加载空字符串..
再次抱歉..