---
title: "How to set shape of Image view in Android"  
description: "In Android, you can use android.widget.ImageView class to display an image file. Image file is easy to use but hard to master,"  
author: "Manoj Pandey"  
published: 2015-06-24  
updated: 2020-04-06  
canonical: https://www.mindstick.com/articles/1796/how-to-set-shape-of-image-view-in-android  
category: "android"  
tags: ["android", "android styles", "image view"]  
reading_time: 2 minutes  

---

# How to set shape of Image view in Android

In Android, you can use android.widget.[ImageView](https://www.mindstick.com/forum/34664/how-to-set-an-image-on-imageview-in-android) class for displaying an image file.

Image file is easy to use but hard to master, because of the various screen and dpi that we have in Android devices.

It displays an arbitrary image like an icon. The ImageView class is capable of loading images from various sources (such as [resources](https://www.mindstick.com/interview/1265/what-are-the-different-types-of-resources-through-which-cold-fusion-can-communicate) or [content providers](https://www.mindstick.com/forum/158888/what-is-the-purpose-of-content-providers-in-android)),

takes care of [computing](https://www.mindstick.com/blog/23070/how-to-get-a-career-in-computing) its measurement from the image so that it is usable in any layout manager, and provides various display options such as scaling and tinting.

Here I am telling you to add the shape of the image view in [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp).

##### Follow the below steps to add shape in image views :

**1.** Create an android projected in eclipse or [Android studio](https://www.mindstick.com/blog/10942/android-studio-vs-eclipse)\
**2.** Add image view in activity_main.xml layout

```
<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=".MainActivity" >     <ImageView        android:id="@+id/myimage4"        android:layout_width="190sp"        android:layout_height="190sp"        android:background="@drawable/myshape"        android:contentDescription="@string/app_name"        android:padding="5sp"        android:scaleType="fitXY"        android:src="@drawable/ic_launcher"        android:visibility="visible" /> </RelativeLayout>
```

**3.** Now right click on the [drawable folder](https://answers.mindstick.com/qa/33493/what-is-a-drawable-folder-on-android) and add a new Android [XML file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp) and Select

shape [Root Element](https://www.mindstick.com/interview/1692/what-is-root-element-in-xml).

![How to set shape of Image view in Android](https://www.mindstick.com/mindstickarticle/b1012df5-bf3c-481b-93da-c28f5e32f59d/images/5a40ab88-d2f0-4387-9c40-c6f7b4a7d9ec.png)

**4.** Now add shape code in myshpae.xml file \

```
 <?xml version="1.0" encoding="UTF-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle" >     <stroke        android:width="2dp"        android:color="#FFFFFFFF" />     <gradient        android:angle="225"        android:endColor="#DD2ECCFA"        android:startColor="#DD000000" />     <corners        android:bottomLeftRadius="7dp"        android:bottomRightRadius="7dp"        android:topLeftRadius="7dp"        android:topRightRadius="7dp" /> </shape>
```

**5.** You have no need to change in MainActivity.class

##### Now run your application

![How to set shape of Image view in Android](https://www.mindstick.com/mindstickarticle/b1012df5-bf3c-481b-93da-c28f5e32f59d/images/eb47fba1-ee08-48f7-8474-2aa05d7e5b40.png)\

---

Original Source: https://www.mindstick.com/articles/1796/how-to-set-shape-of-image-view-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
