Android ViewPager Lag

前端 未结 11 1926
迷失自我
迷失自我 2020-12-28 19:55

Hello I have a viewpager with several pages(using a fragment state pager), and some pngs as backgrounds to those pages. I already followed the Displaying Bitmaps in the Ui (

11条回答
  •  执念已碎
    2020-12-28 20:18

    Building up on @coderek answer I seem to have solved this by fetching bitmaps without scaling them for specific densities:

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inScaled = false;
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resource, opts);
    
    ((ImageView) view).setImageBitmap(bitmap);
    

    Using an image from drawable folder in an xxhdpi device resulted in up to 8 times more memory being allocated!

    P.S.:

    You can also down sample the drawable if the resolution is too big:

    opts.inSampleSize = 2;
    

提交回复
热议问题