Webからの画像を含むいくつかのImageViewを表示するAndroidギャラリーウィジェットがあります。画像はjpgとして保存され、ImageViewsに追加される前にビットマップに変換されます。各jpgは8kbです。画像のスケーリングは行っていません。
1枚または2枚の写真でギャラリーを使用すると、正常に動作し、スクロールがスムーズになります。3枚では少し途切れがちになり、5枚または10枚の写真ではアプリケーションがほとんど使用できなくなります。
なぜパフォーマンスがそんなに悪いのかについて誰かが何か考えを持っていますか?誰かが代替案の提案がありますか?ありがとうございました-
@elevine:jpg urlからビットマップを作成する私の方法:
private Bitmap getBitmapFromURL(String input) throws IOException {
URL url = new URL(input);
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
return bm;
}
これは、ImageAdapterからのgetViewメソッドです。これが私の問題の原因だと思い始めています...画像を何度も取得しすぎていませんか?ご協力いただきありがとうございます!
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
Bitmap bm;
try {
imageView.setImageBitmap(getBitmapFromURL(urls.get(position)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//mageView.
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(new Gallery.LayoutParams(100,100));
return imageView;
}