Introduction
This article explains BitMaps in Android. Android Studio is used to create the sample.
When we download images they come in many sizes that we want for the user interface. When you load an image from the internet, sometimes it might happen that an outOfMemoryException occurs due to the large size of an image. Android phone memory is very limited so we should not use any image that is larger than needed. This application will show you how to load a large image into memory without the outOfMemoryException.
Step 1
Create a project like this:
Click "Next".
Click "Next".
Click "Next".
Click "Finish".
Step 2
Create an XML file with the following.
In the XML file, you will use the imageView inside the RelativeLayout. ImageView that contains the image after resizing.




- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context=".MainActivity">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/imageview"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/button1"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="300dp"
- android:text="Button"
- />
- </RelativeLayout>

Join the conversation! Your thoughts help the community grow.