我正在编写一个应用程序,它本质上是一个翻转卡,在一侧显示单词/提示,在另一侧显示与之相关的图片。我使用 viewflipper 来查看两个视图。问题是图片从互联网加载。应用程序访问数据库,提取url然后加载图片。这意味着视图的变化与下载图片所需的时间一样多。我想立即翻转卡片并加载图片,这样用户就不会认为应用程序很慢。他们应该知道图片正在加载,因此延迟。请建议改进代码。我在翻转卡中加载图片的代码是:
public void setBMP(String s) //String passed is url extracted from column of db uing
{ //internal db
try{
//String url1 = "c.getString(3)";
String url1= s;
System.out.println(url1);
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
{
im.setImageBitmap(bmp);
}
else
System.out.println("The Bitmap is NULL");
}catch(Exception e){}
}
}
为了改变视图,我设置了 actionListener。只要用户触摸屏幕卡翻转和图像加载。
也可以在用户查看其他卡片时在后台预加载图像。或者是否可以缓存查看的卡片?