私のアプリケーションでは、データベースからいくつかの URL を読み込み、それらを に保存しArrayList<Bitmap>
てギャラリーに配置します。うまく機能しますが、非常に遅いです。ArrayList
問題は、画像を表示する前にすべてのビットマップをロードすることです。
try
{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++)
{
Temp = jArray.get(i).toString();
HttpURLConnection connection = null;
try
{
connection = (HttpURLConnection) new URL(Temp).openConnection();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
connection.connect();
InputStream input = connection.getInputStream();
x = BitmapFactory.decodeStream(input);
bitmapArray.add(x);
}
}
return bitmapArray; // returning the array list with all the bitmaps inside
protected void onPostExecute(ArrayList<Bitmap> donnees)
{
SetupInterface(); // This method sends the arraylist to an image adatper and display bitmaps to the screen.
}
私の問題はSetupInterface()
、配列がいっぱいになって返されたときにのみ呼び出されることです。したがって、アクティビティを開くと、ギャラリーを表示するのに約 4 ~ 5 秒かかります。これは、表示する前に配列内のすべてのビットマップを読み込む必要があるためです。より速くする方法は?