Picasso and Glide
Picasso and Glide, Using libraries in Android
Picasso:
A powerful image downloading and caching library for Android.
Images add much-needed context and visual flair to Android applications.
Picasso allows for hassle-free image loading in your application—often in one line of code!
Many common pitfalls of image loading on Android are 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.
Glide:
Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.
Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug in to almost any network stack. By default Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug in to Google’s Volley project or Square’s OkHttp library instead.
Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.
Sample pictures
Java code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package com.example.picasso_glide; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.squareup.picasso.Picasso; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView image1 = findViewById(R.id.imageView1); ImageView image2 = findViewById(R.id.imageView2); String image1Url = "https://wallpapercave.com/wp/wp7911121.jpg"; String image2Url = "https://wallpapercave.com/uwp/uwp552608.jpeg"; Glide.with(this).load(image1Url) .transform(new RoundedCorners(30)) .into(image1); Picasso.get().load(image2Url) .resize(600,500) .into(image2); } } |
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/colorAccent" tools:context=".MainActivity" android:weightSum="2"> <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginStart="8dp" android:layout_marginTop="100dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:layout_weight="1" android:contentDescription="@string/image_1" android:scaleType="center" app:srcCompat="@color/colorPrimary" /> <ImageView android:id="@+id/imageView2" android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginStart="8dp" android:layout_marginTop="100dp" android:layout_marginEnd="8dp" android:layout_marginBottom="100dp" android:layout_weight="1" android:contentDescription="@string/image_2" android:scaleType="center" app:srcCompat="@color/colorPrimaryDark" /> </LinearLayout> |