1. The Setimageresource is synchronized, and the resource images are read and decoded in the main thread. The setimagedrawable is asynchronous.
2. Difference in loading speed. Setimageresource faster than Setimagedrawable and Setimagebitmap.
/*** Sets a drawable as the content of this ImageView. * * <p class= "Note" >this does Bitmap reading and decoding on the UI * thread, which can cause a latency HICC Up. If that ' s a concern, * consider using {@link#setImageDrawable (android.graphics.drawable.Drawable)} or * {@link#setImageBitmap (ANDROID.GRAPHICS.BITMAP)} and * {@linkAndroid.graphics.BitmapFactory} instead.</p> * *@paramresId The resource identifier of the drawable * * @attr ref Android. R.STYLEABLE#IMAGEVIEW_SRC*/@android. View.remotableviewmethod Public voidSetimageresource (intresId) { if(MUri! =NULL|| Mresource! =resId) { Final intOldWidth =Mdrawablewidth; Final intOldHeight =Mdrawableheight; Updatedrawable (NULL); Mresource=resId; MUri=NULL; ResolveUri (); if(oldwidth! = Mdrawablewidth | | OldHeight! =Mdrawableheight) {requestlayout (); } invalidate (); } }
/*** Sets a drawable as the content of this ImageView. * * @paramdrawable the drawable to set*/ Public voidsetimagedrawable (drawable drawable) {if(Mdrawable! =drawable) {Mresource= 0; MUri=NULL; Final intOldWidth =Mdrawablewidth; Final intOldHeight =Mdrawableheight; Updatedrawable (drawable); if(oldwidth! = Mdrawablewidth | | OldHeight! =mdrawableheight) {requestlayout (); } invalidate (); } }
/** * Sets a Bitmap as the content of this ImageView. * @param BM The bitmap to set */ @android. View.remotableviewmethod Public void Setimagebitmap (Bitmap BM) { // If this was used frequently, may handle bitmaps explicitly< c18/>/ to reduce the intermediate drawable object setimagedrawable (new bitmapdrawable (Mcontext.getresources (), BM); }
The difference between Android ImageView Setimagedrawable and Setimageresource