Android development uses the Android-query framework, which is faster and easier to read than the code to be written in traditional android development.
Download the document and its example and package address: http://code.google.com/p/android-query/
Some of my learning experiences are as follows:
Section 1:
// The AQuery class must be implemented
AQuery aq = new AQuery (view );
// Analysis in sequence: Get the Control id corresponding to xml, set the image, set to display, and click the event (the someMethod method must be public)
Aq. id (R. id. icon). image (R. drawable. icon). visible (). clicked (this, "someMethod ");
// Set text content
Aq. id (R. id. name). text (content. getPname ());
Aq. id (R. id. time). text (FormatUtility. relativeTime (System. currentTimeMillis (), content. getCreate (). visible ();
Aq. id (R. id. desc). text (content. getDesc (). visible ();
AQuery also supports Fragment:
@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ){
View view = inflater. inflate (getContainerView (), container, false );
Aq = new AQuery (getActivity (), view );
Return view;
}
Section 2: Use AQuery to asynchronously load images
2.1 read images from the Internet
Aq. id (R. id. image1). image ("image URL ");
2.2 Cache Control: if the image size is too large, the memory cache should be avoided.
Boolean memCache = false;
boolean fileCache = true; aq.id(R.id.image1).image("http://www.vikispot.com/z/images/vikispot/android-w.png", memCache, fileCache);
2.3 When downloading too many images, the image sampling rate needs to be reduced. The fourth parameter generally ranges from 200 to 399 aq to ensure image quality. id (R. id. image1 ). image (imageUrl, true, true, 200, 0 );
2.4 If the image fails to be downloaded, the solution is as follows: 1. set a predefined image. 2. make imageview invisible or gone aq. id (R. id. image1 ). image (imageUrl, true, true, 0, R. drawable. default_image); aq. id (R. id. image1 ). image (imageUrl, true, true, 0, AQuery. INVISIBLE); aq. id (R. id. image1 ). image (imageUrl, true, true, 0, AQuery. GONE); 2.5 Image preload // get small image String thumbnail = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_s.jpg"; Bitmap preset = aq from the previous url. getCachedImage (thumbnail); // display the small image String imageUrl = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_ B .jpg"; aq. id (R. id. image ). image (imageUrl, false, false, 0, 0, preset, AQuery. FADE_IN );
2.6 display progress bar when loading the image, progress input id String imageUrl = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_ B .jpg"; aq. id (R. id. image ). progress (R. id. progress ). image (imageUrl, false, false );
2.7 The image rounded corner is displayed. ImageOptions = new ImageOptions (); options for large images are not supported. round = 15; aq. id (R. id. image ). image (url, options );
2.8 image length/width ratio // retain the original image ratio aq. id (R. id. image ). image (imageUrl, true, true, 0, 0, null, AQuery. FADE_IN, AQuery. RATIO_PRESERVE); // custom image ratio //, a square aq. id (R. id. image2 ). image (imageUrl, true, true, 0, 0, null, 0, 1.0f/1.0f); aq. id (R. id. image3 ). image (imageUrl, true, true, 0, 0, null, 0, 1.5f/1.0f); // 16:9, a video thumbnail aq. id (R. id. image4 ). image (imageUrl, true, true, 0, 0, null, 0, 9.0f/16366f); aq. id (R. id. image5 ). image (imageUrl, true, true, 0, 0, null, 0, 3.0f/4.0f );
2.9 if the image is too high, it can be used to describe which part of the image is used to Display Anchor values: 1.0: Display top of the image0: Display the center of the image-1.0: display bottom of the imageAQuery. ANCHOR_DYNAMIC: Display image with a top bias for photos. ========================================================== ================== ImageOptions options = new ImageOptions (); options. ratio = 1; options. anchor = 1.0; aq. id (R. id. image1 ). image (imageUrl, options );
2.10 processing aq. id (R. id. image1). image (imageUrl, true, true, 0, 0, new BitmapAjaxCallback () {}) after the custom image is loaded (){});
2.11 asynchronously load images from files. We recommend that you reduce the sampling rate to avoid oom File = new file (path); // load image from File, down sample to target width of 300 pixels aq. id (R. id. avatar ). image (file, 300); // load image from file with callback aq. id (R. id. avatar ). image (file, false, 300, new BitmapAjaxCallback () {@ Override public void callback (String url, ImageView iv, Bitmap bm, AjaxStatus status) {iv. setImageBitmap (bm );}});
2.12 if the previous image ("url") is successful, you can use it directly without re-accessing the network. That is to say, you can access the image resources offline.
2.13 obtain the buffer image File file = aq. getCachedFile (url) in the File );
2.14 apart from imageview, webview can also be used to put aq. id (R. id. web). progress (R. id. progress). webImage (url );
2.15 delayed image loading to help you determine whether to load the listview that is rolling quickly. For more information, see the documentation.
2.16 The image does not use the cache aq. id (R. id. image). image (url, false, false );
2.17 cache configuration. The cache is generally stored in the internal File system, but can also be saved in the SDCard File ext = Environment. getExternalStorageDirectory (); File cacheDir = new File (ext, "myapp"); AQUtility. setCacheDir (cacheDir );
2.18 share images. To share images with other programs, you need to put the files in SDCard. The makeSharedFile method creates a copy of the cache address File file = aq. makeSharedFile (url, "android.png"); if (file! = Null) {Intent intent = new Intent (Intent. ACTION_SEND); intent. setType ("image/jpeg"); intent. putExtra (Intent. EXTRA_STREAM, Uri. fromFile (file); startActivityForResult (Intent. createChooser (intent, "Share via:"), SEND_REQUEST );}
2.19 configuration. It is best to write the configuration in the onCreate method of the application. For details, refer to the documentation.
2.20 when the program exits, clear the cache if (isTaskRoot () {AQUtility. cleanCacheAsync (this) ;}or: if (isTaskRoot ()){// Clean the file cache with advance option long triggerSize = 3000000; // clear long targetSize = 2000000 when it is greater than 3 M; // until it is less than 2 M AQUtility. cleanCacheAsync (this, triggerSize, targetSize );}
2.21 low memory processing public class MainApplication extends Application {@ Override public void onLowMemory () {// clear all memory cached images when system is in low memory // note that you can configure the max image cache count, see CONFIGURATION BitmapAjaxCallback. revoke AchE ();