Image performance! Fast loading images! in your app is always a must task to give a better user experience. But in Android apps it has been a tedious task to achieve. Google also has documentation on ‘Managing Bitmap Memory’ which helps to achieve this task but its relatively very complex.
The documentation outlines :
- Cache and recycle bitmaps in memory
- Java classes named LruCache and MutableSet<SoftReference<Bitmap>>?
This is not a problem that I think the developer should not concern as they want to build the app.
Let’s say that a Xamarin. Forms have the page which has lots of images to load- ImagePage.xaml.cs
<?xml version=“1.0” encoding=“utf-8” ?>
<Grid x:Name=“MainGrid” ColumnSpacing=“0” RowSpacing=“0”>
Google’s response to this complex problem is to use a Java library named Glide:
Note: For most cases, we recommend that you use the Glide library to
fetch, decode, and display bitmaps in your app. Glide abstracts out
most of the complexity in handling these and other tasks related to
working with bitmaps and other images on Android. For information
about using and downloading Glide, visit the Glide repository on
Glide handles a lot of details for you:
- Downloads images from URLs
- Handles device rotation
- Handles in-memory and on-disk caching
- Can crop, place a loading indicator, etc.
So if Glide is written in Java, how do we use it in Xamarin.Forms?
To unlock the power of Glide, I created “GlideX”: a simple library to swap-in Glide’s image loading implementation in-place of what Xamarin.Forms ships in the box. This began as an experiment, but perhaps one day could be the default for Xamarin.Forms?
How do I use GlideX in my Xamarin.Forms app?
This part is pretty easy:
- Add the glidex.forms NuGet package to the Android project in your solution.
- Add one line of code to initialize GlideX.
In your MainActivity.cs: