android background image slows down app

后端 未结 6 1574
栀梦
栀梦 2020-12-09 21:32

I am using a viewpager to swipe amongst fragments in my app. I define the background in the XML, so

android:background=\"@drawable/bg_final\"
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 21:39

    I'm a bit late, but this just bit me, and when running the GPU debugger, I noticed that the system scaled up my image! I had a 1920x1080 image, and it showed up as a 3780x6720 texture!

    Ideally, you should have textures for each density in the respective folder (res/drawable-mdpi, res/drawable-hdpi, etc).

    However, if you think your one texture is fine, put it into res/drawable-nodpi, not res/drawable. If you put it into res/drawable-nodpi, the system won't scale it up based on the dpi.

    In my case, it changed a simple UI from 10fps on a Pixel XL to the full frame rate of 60fps.

提交回复
热议问题