android - Gif image view very, very laggy -


i trying disply gif , works great in emulator, on real device it's laggy. have samsung galaxy a3 - 2017. tried many libraries glide library, ion library , felipecsl.gifimageview library nothing worked. have tried display gif url , drawable, raw , assets folders nothing. ideas?

currently have in project:

layout:

<com.felipecsl.gifimageview.library.gifimageview     android:id="@+id/gifimageview"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_above="@+id/bottomnavbar"/> 

mainactivity:

public class mainactivity extends appcompatactivity {  gifimageview gifimageview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      gifimageview = (gifimageview) findviewbyid(r.id.gifimageview);      bottomnavigationview bottomnavigationview = (bottomnavigationview) findviewbyid(r.id.bottomnavbar);     bottomnavigationview.setonnavigationitemselectedlistener(new bottomnavigationview.onnavigationitemselectedlistener() {         @override         public boolean onnavigationitemselected(@nonnull menuitem item) {             switch (item.getitemid())             {                 case r.id.back:                     toast.maketext(mainactivity.this, "previous", toast.length_short).show();                     break;                  case r.id.start:                     //toast.maketext(mainactivity.this, "start gif", toast.length_short).show();                     new retrivebytearray().execute("http://gifdanceparty.giphy.com/assets/dancers/smooch.gif");                     gifimageview.startanimation();                     break;                  case r.id.stop:                     //toast.maketext(mainactivity.this, "stop gif", toast.length_short).show();                     gifimageview.stopanimation();                     break;                  case r.id.share:                     toast.maketext(mainactivity.this, "share", toast.length_short).show();                     break;                  case r.id.next:                     toast.maketext(mainactivity.this, "next", toast.length_short).show();                     break;             }             return true;         }     }); } 

retrivebytearray:

private class retrivebytearray extends asynctask<string, void, byte[]> {      @override     protected byte[] doinbackground(string... strings) {         try {             url url = new url(strings[0]);             httpurlconnection urlconnection = (httpurlconnection)url.openconnection();             if (urlconnection.getresponsecode() == 200)             {                 inputstream in = new bufferedinputstream(urlconnection.getinputstream());                 bytearrayoutputstream buffer = new bytearrayoutputstream();                 int nread;                 byte[] data = new byte[10240];                 while ((nread = in.read(data, 0, data.length)) != -1)                 {                     buffer.write(data, 0, nread);                 }                 buffer.flush();                 return buffer.tobytearray();             }         } catch (ioexception e) {             e.printstacktrace();         }         return null;     }      @override     protected void onpostexecute(byte[] bytes) {         super.onpostexecute(bytes);         gifimageview.setbytes(bytes);     } } 

fix edit

to wants know how fixed ( tgmcians answer):

add dependencies:

`compile 'com.facebook.fresco:fresco:1.4.0' // animated gif support compile 'com.facebook.fresco:animated-gif:1.4.0'` 

layout:

 <com.facebook.drawee.view.simpledraweeview     android:id="@+id/my_image_view"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_centervertical="true"     android:layout_centerhorizontal="true"     /> 

mainactivity:

public class mainactivity extends appcompatactivity {  simpledraweeview msimpledraweeview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     fresco.initialize(this);     setcontentview(r.layout.activity_main);      msimpledraweeview = (simpledraweeview) findviewbyid(r.id.my_image_view);   draweecontroller controller = fresco.newdraweecontrollerbuilder()                             .seturi("https://media4.giphy.com/avatars/100soft/wahneddlgjrz.gif")                             .setautoplayanimations(true)                             .build();                     msimpledraweeview.setcontroller(controller); 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -