Search⌘ K
AI Features

Handling and Displaying Images

Explore how to handle and display images in Android applications. Learn to use ImageView for static images and implement the Fresco library for loading images from URLs, managing caching and memory efficiently. This lesson equips you with practical skills to manage image display in your Android projects.

Introduction

In this lesson, we’ll learn how to handle and display images in Android apps. We’ll start with a simple example and learn how to display a static image in an activity, and then move on to more complex use cases, such as displaying images from a URI, caching images, and so on.

Displaying a static image

A static image can be displayed using an ImageView with a Drawable set as its source.

Let’s define an ImageView in the activity resource file and set its android:src to a drawable file.

XML
<ImageView
android:id="@+id/image_view"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_overflow_holo_dark"
android:contentDescription="@string/simple_image" />

Also, instead of setting the src in the XML file, we can do it ...