ImageView the way to set up the picture has many clocks, can write in the XML android:src= "@drawable/xxx", can also be set in Java code.
There are several ways to set up in Java, including:Setimageresource,setimagedrawable,setimagebitmap.
In the XML is set in fact and in the Java call Setimageresource is the same, of course, XML more than a parsing process, put in Java code call will be slightly better (actually no difference).
3 different ways to set up pictures:
(1) The setimageresource parameter is resid and must be a resource in the drawable directory. In addition, comments are indicated in the Setimageresource method
* <pclass= "note" >this does Bitmap reading and decoding on the UI
* thread, which can cause a latency hiccup. If that ' s a concern,
* Consider using {@link #setImageDrawable (android.graphics.drawable.Drawable)}or
* {@link #setImageBitmap (Android.graphics.Bitmap)} and
* {@link android.graphics.BitmapFactory} instead.</p>
This method reads and parses the picture in the UI thread, so it is possible to delay the start of an activity. So if you are concerned about this official proposal to replace it with Setimagedrawable and Setimagebitmap.
(2) The setimagebitmap parameter is bitmap, which can parse images from different sources and set them up. But let's look at the source code of Setimagebitmap:
@android. View.remotableviewmethod
public void Setimagebitmap (Bitmap bm) {
If this is used frequently, mayhandle bitmaps explicitly
To reduce the intermediate drawable object
Setimagedrawable (Newbitmapdrawable (Mcontext.getresources (), BM));
}
What Setimagebitmap actually do is to encapsulate the bitmap object as a Drawable object, and then call Setimagedrawable to set the picture. Therefore, the code is written in the suggestion, if you need to call this method frequently, it is best to encapsulate a fixed drawable object, call setimagedrawable directly, this can reduce the Drawable object. Because each call to the Setimagebitmap method will have a drawable to the bitmap object.
(3) setimagedrawable parameter is drawable, but also can accept different sources of pictures, the way to do is to update the ImageView picture. The last two methods actually call the Setimagedrawable (Setimageresource is not called directly, but the updated method is the same as setimagedrawable).
So a comprehensive view of setimagedrawable is the most efficient memory, if you worry about the picture too large or too many images affect memory and load efficiency, you can parse the picture and then call the Setimagedrawable method to set.
Setimageresource and Setimagedrawable differences