Android (初学者)如何将网站上的图像自动加载到imageview中
我正在为好友搞笑图片网站开发一个应用程序。我从android开发者网站下载了gridview活动,但它只加载预设的图像URL,这对我们来说根本不起作用。我们需要一个图像加载器,可以自动从网站加载图像 任何帮助都将不胜感激。试试这个Android (初学者)如何将网站上的图像自动加载到imageview中,android,eclipse,gridview,imageview,Android,Eclipse,Gridview,Imageview,我正在为好友搞笑图片网站开发一个应用程序。我从android开发者网站下载了gridview活动,但它只加载预设的图像URL,这对我们来说根本不起作用。我们需要一个图像加载器,可以自动从网站加载图像 任何帮助都将不胜感激。试试这个 Drawable drawable = LoadImage(<Replace this with your url> + UserProfile.Photo); UserPhotoImageView.setImageDrawable(drawable);
Drawable drawable = LoadImage(<Replace this with your url> + UserProfile.Photo);
UserPhotoImageView.setImageDrawable(drawable);
<replace with Your Image View>.setImageDrawable(drawable);
public Drawable LoadImage(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}
catch (Exception e)
{
System.out.println("Exc=" + e);
return null;
}
}
Drawable-Drawable=LoadImage(+UserProfile.Photo);
UserPhotoImageView.setImageDrawable(可绘制);
.setImageDrawable(可绘制);
公共可绘制加载映像(字符串url)
{
尝试
{
InputStream为=(InputStream)新URL(URL).getContent();
Drawable d=Drawable.createFromStream(是“src名称”);
返回d;
}
捕获(例外e)
{
System.out.println(“Exc=“+e”);
返回null;
}
}
试试这个
Drawable drawable = LoadImage(<Replace this with your url> + UserProfile.Photo);
UserPhotoImageView.setImageDrawable(drawable);
<replace with Your Image View>.setImageDrawable(drawable);
public Drawable LoadImage(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}
catch (Exception e)
{
System.out.println("Exc=" + e);
return null;
}
}
Drawable-Drawable=LoadImage(+UserProfile.Photo);
UserPhotoImageView.setImageDrawable(可绘制);
.setImageDrawable(可绘制);
公共可绘制加载映像(字符串url)
{
尝试
{
InputStream为=(InputStream)新URL(URL).getContent();
Drawable d=Drawable.createFromStream(是“src名称”);
返回d;
}
捕获(例外e)
{
System.out.println(“Exc=“+e”);
返回null;
}
}
使用懒汉列表下载
使用懒人列表下载
我认为最好的方法是使用一个。它将允许您在SD卡和内部存储器上进行延迟加载和缓存。简而言之,它使事情变得更简单,并允许您以尽可能快的速度完成。试试看。与其他人的建议不同,我认为最好的方法是使用一个。它将允许您在SD卡和内部存储器上进行延迟加载和缓存。简而言之,它使事情变得更简单,并允许您以尽可能快的速度完成。试试看。希望库是您希望在
图像视图上轻松加载图像的工具。希望库是您希望在图像视图上轻松加载图像的工具。我可以看到初学者提出的下一个问题:“我得到了一个网络,没有ReadException”。你应该试着解释一下,并在回答中表现出一些努力。“试试这个[一些代码]”没什么。。。(除了那些丑陋的东西:System.out.println()
)我可以看到初学者的下一个问题:“我得到了一个NetworkOnIthReadException”。你应该试着解释一下,并在回答中表现出一些努力。“试试这个[一些代码]”没什么。。。(除了那些丑陋的东西:System.out.println()
)