Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid listview image lag
    primarykey
    data
    text
    <p>My app contains a listview which can optionally contain images from a users sd card. It works fine however when any image is loaded there is noticeable lag. I have this in my getView:</p> <pre><code> BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeFile(image, o); final int REQUIRED_SIZE=70; //Find the correct scale value. It should be the power of 2. int width_tmp=o.outWidth, height_tmp=o.outHeight; int scale=1; while(true){ if(width_tmp/2&lt;REQUIRED_SIZE || height_tmp/2&lt;REQUIRED_SIZE) break; width_tmp/=2; height_tmp/=2; scale++; } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize=scale; Bitmap myBitmap = BitmapFactory.decodeFile(image, o2); image_main.setImageBitmap(myBitmap); </code></pre> <p>Any suggestions?</p> <p>EDIT: Replaced the above with this but no images are loading...</p> <pre><code> class Thumbnailer extends AsyncTask&lt;String, Void, Bitmap&gt; { String image; @Override protected void onPostExecute(Bitmap result) { image_main.setImageBitmap(result); } @Override protected void onProgressUpdate(Void... progress) { } @Override protected Bitmap doInBackground(String... params) { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeFile(image, o); final int REQUIRED_SIZE=70; //Find the correct scale value. It should be the power of 2. int width_tmp=o.outWidth, height_tmp=o.outHeight; int scale=1; while(true){ if(width_tmp/2&lt;REQUIRED_SIZE || height_tmp/2&lt;REQUIRED_SIZE) break; width_tmp/=2; height_tmp/=2; scale++; } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize=scale; return BitmapFactory.decodeFile(image, o2); } } new Thumbnailer().execute(image); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload