您好我面临一个特殊的问题,我需要下载图像并将其显示在ListView对应的特定对象上TextView's.我的代码是成功显示TextView's我需要显示但我不知道如何在我的文本视图旁边显示所有这些不同的图像ListView.
经过SO中的许多线程之后.最佳答案是通过1.懒惰列表2.通用图像加载器来解决这个问题
我已经完成了两个解决方案.我下载了Lazy List代码,其中URL是存储在Array中的硬编码字符串.我想做的是动态创建自己的字符串.将它们存储在缓存中并显示所有相应的图像.
这是我的代码:
public class Tools_ListItemActivity extends ListActivity
{
private Context context;
String s;
private static final String TAG_POSTS = "posts";
private static final String TAG_MDNAME = "mdname";
private static final String TAG_UTCOST = "utcost";
private static final String TAG_IIMG= "iimg";
JSONArray posts = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
s=getIntent().getExtras().getString("url");
new ProgressTask(Tools_ListItemActivity.this).execute();
}
@Override
protected void onListItemClick(ListView l, View v, int …Run Code Online (Sandbox Code Playgroud) 我成功地将通用图像加载程序库(1.8.3版本)应用到我的应用程序,我正在尝试调整图像大小,然后在gridview项目中显示它(因为有时图像太大而无法将其缓存在内存中.)
这是我正在尝试的:
...
BitmapFactory.Options resizeOptions = new BitmapFactory.Options();
resizeOptions.inSampleSize = 3; // decrease size 3 times
resizeOptions.inScaled = true;
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.blank)
.showImageForEmptyUri(R.drawable.no_image)
.cacheInMemory()
.cacheOnDisc()
.decodingOptions(resizeOptions)
.build();
...
Run Code Online (Sandbox Code Playgroud)
由于某种原因,此代码不会使图像缩小3倍.
有人有更好的方法来按照指定的密度调整图像大小吗?
我正在使用UIL(由Nosotra)下载服务器渲染的图像,并且服务器最多需要50秒来创建每个图像.服务器的超时设置为15秒,因此我们创建了一个在ImageDownloader.getStream()方法中实现的轮询机制.下载后,图像将显示在ViewPager中(android.support.v4.view.ViewPager就像样本一样).
当用户导航到其他页面时,我希望在不下载文件的情况下停止轮询,但似乎没有" 好 "方法来打破下载流程.
getStream伪代码
1. Parse custom-style URI ("asdf://mypng|123455678945643563245");
2. Make a real world URL from it.
3. Poll the server for the image url (causes the server to render - could take up to 1m30s).
4. Get the stream from the URL, return the stream to caller.
Example Code: InputStream is = (InputStream) url.getContent();
Run Code Online (Sandbox Code Playgroud)
到目前为止尝试了什么
null从我的getStream方法返回会导致NullPointerException抛出,所以它与抛出异常基本相同.
抛出异常时,图像会停止,但是:
OutOfMemoryError,所以我在屏幕上显示错误.我不应该得到错误.我已经尝试过这个SO问题的清单 …