Android ImageView example tutorial via XML

Use imageView inside android application to display image in relativelayout.

Image view is used to display image inside android applications. App developer can set any image from drawable resource folder and add that image inside imageview. So my in this tutorial i am adding image via activity_main.xml layout file and set image resource is drawable-hdpi folder. So here is the complete step by step tutorial for Android ImageView example tutorial via XML.

android-project-download-code-button

Android ImageView example tutorial via XML.

Copy your image( Which you want to display using imageView ) into drawable-hdpi folder.

drawable hdpi folder

Download below image and copy into drawable-hdpi folder.

demo_image
Code for MainActivity.java file.

package com.androidimageviewexampletutorialxml_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.androidimageviewexampletutorialxml_android_examples.com.MainActivity" >

 <ImageView
 android:id="@+id/imageView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:src="@drawable/demo_image" />

</RelativeLayout>

Screenshot:

Android ImageView example tutorial via XML

Click Here to download Android ImageView example tutorial via XML project.

Leave a Reply

Your email address will not be published. Required fields are marked *