Introduction to the use of Android framework Picasso

Source: Internet
Author: User

Introduction

Images Add much-needed context and visual flair to Android applications. Picasso allows for hassle-free image loading in your application-often on one line of code!

Picasso.with (context). Load ("Http://i.imgur.com/DvpvklR.png"). into (ImageView);

Many common pitfalls of image loading on Android is handled automatically by Picasso:

  • Handling ImageView Recycling and download cancelation in an adapter.
  • Complex image transformations with minimal memory use.
  • Automatic memory and disk caching. Featuresadapter DOWNLOADS

    Adapter re-use is automatically detected and the previous download canceled.

    @Override public void GetView (int position, view Convertview, ViewGroup parent) {  Squaredimageview View = (squaredimag Eview) Convertview;  if (view = = null) {    view = new Squaredimageview (context);  }  String url = getItem (position);  Picasso.with (context). Load (URL). into (view);
    IMAGE transformations

    Transform images to better fit into layouts and to reduce memory size.

    Picasso.with (context).  load (URL).  resize (  ). Centercrop (). into  (ImageView)

    You can also specify custom transformations for more advanced effects.

    public class Cropsquaretransformation implements transformation {@Override public    Bitmap transform (Bitmap source) {int size = Math.min (Source.getwidth (), Source.getheight ());    int x = (Source.getwidth ()-size)/2;    int y = (source.getheight ()-size)/2;    Bitmap result = Bitmap.createbitmap (source, x, y, size, size);    if (Result! = Source) {source.recycle ();  } return result; } @Override Public String key () {return ' square () ';}} 

    Pass an instance of this class to the transform method.

    Place holders

    Picasso supports both download and error placeholders as optional features.

    Picasso.with (context).    load (URL).    placeholder (r.drawable.user_placeholder)    . Error (R.drawable.user_ Placeholder_error)    . into (ImageView);

    A request would be retried three times before the error placeholder is shown.

    RESOURCE LOADING

    Resources, assets, files, content providers is all supported as image sources.

    Picasso.with (context). Load (R.drawable.landing_screen). into (ImageView1); Picasso.with (context). Load (new File (...)). Into (IMAGEVIEW2);
    DEBUG indicators

    For development You can enable the display of a colored ribbon which indicates the image source. Call on the setIndicatorsEnabled(true) Picasso instance.

    The source code to the Picasso, it samples, and this website are available on GitHub.

    Maven
    <dependency>  <groupId>com.squareup.picasso</groupId>  <artifactid>picasso</ Artifactid>  <version>(insert latest version)</version></dependency>
    Contributing

    If you would a-contribute code you can do so through GitHub by forking the repository and sending a pull request.

    When submitting code, * * * Every effort to follow existing conventions and style in order to keep the code as Reada ble as possible. Please also make sure your code compiles by running mvn clean verify .

    Before your code can be accepted to the project you must also sign the individual contributor License Agreement (CLA).

    License
    Copyright Square, inc.licensed under the Apache License, Version 2.0 (the "License"); In compliance with the license.you-obtain a copy of the License at   Http://www.apache.org/licenses/LICENSE-2.0Unle SS required by applicable law or agreed to in writing, softwaredistributed under the License are distributed on a "as is" Basis,without warranties or CONDITIONS of any KIND, either express or implied. See the License for the specific language governing permissions andlimitations under the License.

Introduction to the use of Android framework Picasso

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.