
Copyright statement: This article is the original article for the blogger, without permission may not be reproduced.
Has not used the Picasso image to load the framework, today with the next, very easy to use, simple to write a note!
* Android network loading framework: Picasso, open source address:Http://square.github.io/picasso/
* the framework is developed by Square Android for the development of a set of graphics cache framework to achieve the picture download and cache function
* merit:
* can load local and network pictures
* easy to achieve image transformation operations, such as the size of the change, rotation, etc.
* when you use ListView in Adapter, you can cancel and recycle the current download operation in Adapter.
Public Class MainActivity Extends Activity{
//ImageView control
PrivateLoader_iv ImageView;
/ / pictures address (a Baidu just to find)
PrivateUrl= String"Http://www.3lian.com/gif/DetailView.htm? Detail=http://img4.3lian.com/img2005/08/32/200902271952518342.png";
@Override
Protected Void OnCreate(savedInstanceState Bundle) {
Auto-generated method stub / / TODO
Super.onCreate (savedInstanceState);
SetContentView (R.layout.activity_main);
Loader_iv= (ImageView) findViewById (R.id.loader_iv);
LoadHttpImage ();
OtherMethod ();
}
By using the framework of Picasso / / add network image to ImageView, generally only one line of code can be written
Private Void LoadHttpImage(1)
Picasso.with (This(.Load (URL).Into (loader_iv);/ / this put pictures on the URL to loader_iv ImageView on the loading
}
Several other commonly used methods of /
Private Void OtherMethod(1)
//1, image conversion, convert image size to reduce memory usage
Picasso.with (This(.Load (URL).Resize () ()Sixty,Sixty(.CenterCrop ().Into () (loader_iv);The 60 is the size of the picture.
//2, set the picture to load the error when the picture shows
Picasso.with (This(.Load (URL).Error (R.drawable.ic_launcher).Into (loader_iv) ();
//3, set the picture to load the kind of picture display
Picasso.with (This(.Load (URL).Placeholder (R.drawable.ic_launcher).Into (loader_iv) ();
//3, load the local file image, such as the asserts file under the picture
Picasso.with (This.load () () ()"File:///android_asset/test.png"(.Into) (loader_iv);
}
}
Remember to add Picasso related jar packages and network permissions before use.
- top
- One
- step on
- Zero
- Guess you're looking for