Pages Navigation Menu

Coding is much easier than you think

How To Create Image View in an Android Application using Eclipse:

How To Create Image View in an Android Application using Eclipse:

In this tutorial, you will be Learning, How to display Image View in an activity

Here you go!!!!


Before creating an android application using Eclipse, let us see some of the key terms involved while developing this application.

Key terms involved in this project:

Imageview: Displays an arbitrary image, such as an icon. The ImageView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the image so that it can be used in any layout manager, and provides various display options such as scaling and tinting.

Drawable: A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon. There are several different types of drawables: Bitmap File, Nine-Patch File, Layer list, State List, Level list, Transition Drawable, Inset Drawable, Clip Drawable, Scale Drawable, Shape Drawable. This project requires bitmap file/image file to fill the activity.

Bitmap File: A bitmap image. Android supports bitmap files in a three formats: .png (preferred) .jpg (acceptable), .gif (discouraged). You can reference a bitmap file directly, using the filename as the resource ID, or create an alias resource ID in XML.

The tutorial is about how to display an image file.

This project is developed in Eclipse 4.2 (Juno) and tested with Android 2.2

If you are new to new to android application project, to create a new project in Eclipse refer Creation of Android Project.


Now let’€™s go to the coding section. This project requires following files.

Source Code:

  1. – Activity (main screen)

Activity Files:

  1. activity_image.xml – main screen/ layout

res – Values:

  1. strings.xml -€“ strings available in layout/activity

Manifest file:

  1. AndroidManifest.xml

Here are the coding for the above files.

package com.example.imageview; // Package Image View
import android.os.Bundle; // A mapping from String values to various Parcelable types.
import; // Required to create an activity
import android.view.Menu; //Interface for managing the items in a menu.
public class Image extends Activity { // all class extends Activity
	protected void onCreate(Bundle savedInstanceState) { // Create a new activity
		setContentView(R.layout.activity_image); // display activity image  when app starts


<?xml version="1.0" encoding="utf-8"?>
<!-Setting the linear layout with vertical orientation-->
<LinearLayout xmlns:android=""
<!-- Displays text for the app on the screen -->
<!-- Drawable right refers to the user defined image file in res/drawable -->
android:drawableRight="@drawable/image1" android:padding ="5dp"/>


Menu : activity_image.xml

    <menu xmlns:android="">

Note: Since there are no menu settings involved in this project, delete the contents of the menu settings. This may cause errors in while building the project.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="8" />

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />



<?xml version="1.0" encoding="utf-8"?>
<! -- Application Name -->

    <string name="app_name">Imageview</string>
<! -- Text message -->

    <string name="image">Image successfully loaded</string>


Styles. xml:

<! -- specify properties such as height, padding, font color, font size, background color -->

        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    <style name="AppBaseTheme" parent="android:Theme.Light">
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->


Run the android application:

Android applications can be run on the android devices. You can either connect a hardware to the system to test the application or you can use the android virtual devices (AVD) Manager to create/manage the virtual devices running on emulator to run the application.

If you are new to create a Android Virtual Device (AVD), refer Creating Android Virtual Device.

To run the application/ project, Build your project using Project -> Build Project.

Build project

This will show errors in Console window at the bottom of the working area in case your project contains.

If your build is successful, Run your application using Run -> Run or Press Ctrl +F11.

Run Project

Upon running the application, the emulator will be launched which displays the AVD on your screen.

Start Emulator

You can see your app with the image set during the android project creation in AVD.

AVD_Home screen_7

Now the activity created for image view is shown as in the figure below with the image file available in drawable folder.

Image view

Thus the android application project is executed successfully.


Click Here To Share This..!!

%d bloggers like this: