android - Background image causing lag and frame skipping -


i have simple layout in want background image. first tried put background image through xml there lag.

so followed set image through asynctask still no luck.

image of 1131 x 1800 resolution , size 369kb.

i/choreographer: skipped 33 frames!  application may doing work on main thread. i/choreographer: skipped 37 frames!  application may doing work on main thread. i/choreographer: skipped 34 frames!  application may doing work on main thread. i/choreographer: skipped 34 frames!  application may doing work on main thread. i/choreographer: skipped 34 frames!  application may doing work on main thread. 

java file

public class mainactivity extends flights{ @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     new loaddrawable().execute(); }  private class loaddrawable extends asynctask<drawable, void, drawable> {     @override     protected drawable doinbackground(drawable... params) {         //loading drawable in background         final drawable image = getresources().getdrawable(r.drawable.as);         //after drawable loaded, onpostexecute called         return image;     }      @override     protected void onpostexecute(drawable loaded) {         //hide progress bar         //progressbar progress = (progressbar) findviewbyid(r.id.progress_bar);         //progress.setvisibility(view.gone);         //set layout background loaded drawable         relativelayout layout = (relativelayout) findviewbyid(r.id.root);         layout.setbackgrounddrawable(loaded);     }      @override     protected void onpreexecute() {}      @override     protected void onprogressupdate(void... values) {} }  } 

your image size big. problem in set image background size of image , not fit resolution. had same problem. after search , test many methods, found glide library set image. library, not important device size is. glide set it.

for set image drawable, can code this:

 glide.with(this).load(r.drawable.backtwo).asbitmap().into(new simpletarget<bitmap>(size.x, size.y) {             @override             public void onresourceready(bitmap resource, glideanimation<? super bitmap> glideanimation) {                 drawable drawable = new bitmapdrawable(resource);                 if (build.version.sdk_int >= build.version_codes.jelly_bean) {                     iv_background.setbackground(drawable);                 }             }         }); 

another approach using different image resolution different device screen. weakness of approach increasing apk size


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -