Development of mobile applications is impossible without visual content that makes the interface alive and understandable for the user. If you are just starting your journey in the world Android development, then the issue of integrating graphic elements is one of the very first and critically important. Incorrectly adding assets can lead to compilation errors or incorrect display on different screens.
In this article we will analyze in detail the mechanisms for working with raster and vector graphics within the environment Android Studio. You will learn about the project structure, file naming rules and modern approaches to resource management that are used by professionals in 2026.
The process of installing an image seems trivial, but hides many nuances of memory optimization and interface adaptability. We will look at both the classic approach through XMLand modern methods for Jetpack Compose.
Preparation of graphic files and formats
Before transferring a file to a project, you need to make sure that it meets the technical requirements of the platform. Android supports many formats, but for best performance it is recommended to use specific file types. Raster images, such as JPEG or PNGare great for photos, but take up more space.
For icons, logos and simple graphics, the format has become the de facto standard Vector Drawable. Vector files are scaled without loss of quality and take up negligible space in the application memory. Using vectors allows you to avoid creating multiple copies of the same image for different screen densities.
If you have a source file in SVGformat, you cannot simply copy it into the project. Android Studio provides a built-in converter that converts vector graphics into a XMLformat that the system understands. This is a critical preparation step that beginners often miss.
โ ๏ธ Warning: Never use files with spaces or special characters in the name. The Android resource system only allows lowercase letters, numbers, and underscores.
Use online tools or plugins in graphics editors to pre-optimize PNG files before importing to reduce APK size.
Classic method: Drawable Folder and Resource Manager
The most common The way to add a picture is to place the file in the resources directory. In the Android project structure, all graphic elements are stored in the folder res. Inside it there is a subfolder drawable, which is intended for images that do not depend on the pixel density of a particular device.
Starting with modern versions Android Studio, manual copying of files through the operating system explorer is not recommended. Instead, you should use the built-in tool Resource Manager. It will automatically create the necessary links and check the file for errors. To open it, go to the tab View โ Tool Windows โ Resource Manager.
In the window that opens you will see a list of all available resources. By clicking on the plus in the upper corner, you can select an option Add Image Asset or simply drag the file into the preview area. The system will prompt you to select the target folder, and by default this will be drawable.
- ๐ The file is automatically copied to the directory
src/main/res/drawable. - ๐ A unique resource identifier is created, accessible through
R.drawable.file_name. - โ๏ธ Android Studio generates code to access the image in Java or Kotlin.
- ๐จ Image preview is supported directly inside IDE.
After importing, you can use the image in interface layouts. In XML layout files, this is done through the android:src or android:backgroundattribute. For example, for an element ImageView the code will look like this:
<ImageViewandroid:id="@+id/myImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo" />
โ๏ธ Checking resource import
Optimization for different screens: Mipmap and Density
Although the folder drawable is universal, for icons application there is a special directory - mipmap. Android uses different scaling algorithms for desktop icons and in-app graphics. Placing the launcher icon in mipmap ensures that it will display clearly on devices of all pixel densities.
If you are working with high-resolution raster images that need to look perfect on specific screens, you may need to create density qualifiers. These are subfolders with names like drawable-hdpi, drawable-xhdpi or drawable-xxhdpi. They contain versions of the same image of different sizes.
Modern development practice tends to abandon multiple raster copies in favor of vectors or density-independent resources. However, if your task requires photorealism, this structure cannot be ignored. The system will automatically select the required file depending on the characteristics of the user's screen.
| Qualifier | Density (DPI) | Scale multiplier | Use example |
|---|---|---|---|
mdpi |
160 dpi | 1.0x | Base resolution |
hdpi |
240 dpi | 1.5x | Old smartphones |
xhdpi |
320 dpi | 2.0x | Standard for most |
xxhdpi |
480 dpi | 3.0x | Flagship models |
โ ๏ธ Attention: If you put the image only in a folder without a qualifier (for example, just in drawable), the system will scale it programmatically. This can lead to a โsoapyโ image on high-resolution screens.
Working with vector graphics (VectorDrawable)
Vector graphics in Android are implemented through a class VectorDrawable. It is an XML file that describes an image using coordinates, paths, and colors rather than a grid of pixels. The main advantage of this approach is infinite scalability. You can stretch the icon to fill the entire screen, and it will remain perfectly clear.
To add a vector, use the same Resource Manager. When you import an SVG file, the wizard will prompt you to configure settings such as default size and asset name. After conversion, you will receive an XML code that you can edit manually. This opens up the possibility of complex animations and changing colors through code.
It is important to note that support for vectors was not added immediately. To work on older versions of Android (below 5.0), you need to enable support through the library AndroidX. In the file build.gradle of your module the option must be activated:
android {defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
Using vectors significantly reduces the size of the final APKfile. Instead of storing several megabytes of bitmap images for different screens, you store a single text file several kilobytes in size. This directly affects how quickly the user loads the application.
VectorDrawable Limitations
Complex gradients and blur effects may not display correctly in vector format. In such cases, it is better to use a raster or support library.
Using images in Jetpack Compose
Modern interface development is increasingly moving to declarative toolkit Jetpack Compose. Here the approach to working with resources differs from classic XML. Instead of tags ImageView you use compose tables, such as Imagethat accept objects like Painter.
To load an image from resources in Compose, use the function painterResource. It takes a resource ID and returns an object ready to be rendered. The syntax becomes more concise and readable, making it easier to maintain the code in large projects.
An example code for displaying an image in Compose is as follows:
@Composablefun MyScreen() {
Image(
painter = painterResource(id = R.drawable.logo),
contentDescription = "Company Logo",
modifier = Modifier.size(200.dp)
)
}
Pay attention to the parameter contentDescription. This is a required Accessibility field that allows screen readers to describe an image to visually impaired users. Ignoring this parameter is considered a violation of the guidelines Google Play.
Frequent errors and problem solving
Even experienced developers encounter problems when working with resources. One of the most common mistakes is Unresolved reference. This occurs if you added a file to a folder but did not sync the project. Always click the Sync Now button after making any changes to the folder structure.
Another common problem is an incorrect file extension. Android Studio may not recognize the image if it has a double extension, for example image.png.jpg. Make sure the file name is clean and follows naming conventions. Also check whether the file name is reserved by system classes.
If the image appears as a black square or is not visible at all, check its color. A white icon on a white background will be invisible. Use layout debugging tools (Layout Inspector) to see the actual boundaries of the element.
โ ๏ธ Attention: The Android Studio interface and menu names may change slightly with the release of new versions of the IDE. If you do not find the described option, use the settings search (Ctrl+Shift+A).
Always use Resource Manager for import to avoid path errors and automatically update the R resource index.
FAQ: Frequently Asked Questions
Why is my image not showing up in the preview?
Most often the problem lies in the IDE cache. Try running the command File โ Invalidate Caches / Restart. Also make sure that the file is not damaged and is in a supported format.
Is it possible to download pictures from the Internet directly?
Yes, but this requires third-party libraries such as Glide or Coil. Standard Android tools are not designed for efficient caching and loading of network images.
How to change the transparency of an image in code?
In XML, use an attribute android:alpha with a value from 0.0 to 1.0. In Kotlin, for ImageView you can call the method imageview.alpha = 0.5f.
What is the difference between src and background for an ImageView?
The attribute src displays the image itself taking into account the scale of the content. The attribute background draws a picture behind the view, stretching it over the entire area of the element, which can distort the proportions.