ListView very slow when scrolling (using ViewHolder/recycling)

后端 未结 10 505

I\'m back at trying out some Android dev again. I have an \"old\" HTC Hero phone lying around, so I booted that one up, did some updates and are now up n running again with Ecli

10条回答
  •  悲哀的现实
    2021-02-02 17:08

    This Might help some one

    If you have an image in your list Item, you have to remember to reduce the quality of that Image. It's allot faster to load in a few Kb's than a few megabytes.

    This helped me

     public Bitmap MakeFileSmaller_ToBitmap(File f) {
            try {
                // Decode image size
                BitmapFactory.Options o = new BitmapFactory.Options();
                o.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(new FileInputStream(f), null, o);
    
                // The new size we want to scale to
                final int REQUIRED_SIZE=200;
    
                // Find the correct scale value. It should be the power of 2.
                int scale = 1;
                while(o.outWidth / scale / 2 >= REQUIRED_SIZE &&
                        o.outHeight / scale / 2 >= REQUIRED_SIZE) {
                    scale *= 2;
                }
    
                // Decode with inSampleSize
                BitmapFactory.Options o2 = new BitmapFactory.Options();
                o2.inSampleSize = scale;
                return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
            } catch (FileNotFoundException e) {
                Log.d(TAG, "FILE NOT FOUND " );
            }
            Log.d(TAG, "OTHER EXCEPTION");
    
            return null;
        }
    

提交回复
热议问题