# ShapeableImageView

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/imageview/ShapeableImageView.java)

*** ** * ** ***


```
public class ShapeableImageView implements Shapeable
```

<br />

*** ** * ** ***

An ImageView that draws the bitmap with the provided Shape.

## Summary

| ### Public fields |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#shapeAppearanceModel()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#strokeColor()` |
| `float` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#strokeWidth()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#ShapeableImageView(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#ShapeableImageView(Context,AttributeSet)(Context context, AttributeSet attrs)` |
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#ShapeableImageView(Context,AttributeSet,int)(Context context, AttributeSet attrs, int defStyle)` |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getContentPaddingBottom()()` The additional padding on the bottom of the image, which is not applied to the background. |
| `final int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getContentPaddingEnd()()` The additional relative padding on the end of the image, which is not applied to the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getContentPaddingLeft()()` The additional padding on the left of the image, which is not applied to the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getContentPaddingRight()()` The additional padding on the right of the image, which is not applied to the background. |
| `final int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getContentPaddingStart()()` The additional relative padding on the start of the image, which is not applied to the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getContentPaddingTop()()` The additional padding on the top of the image, which is not applied to the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getPaddingBottom()()` The padding on the bottom of the View, applied to both the image and the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getPaddingEnd()()` The relative padding on the end of the View, applied to both the image and the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getPaddingLeft()()` The padding on the left of the View, applied to both the image and the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getPaddingRight()()` The padding on the right of the View, applied to both the image and the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getPaddingStart()()` The relative padding on the start of the View, applied to both the image and the background. |
| `int` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getPaddingTop()()` The padding on the top of the View, applied to both the image and the background. |
| `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getShapeAppearanceModel()()` Returns the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` used for the shape definition. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getStrokeColor()()` Returns the stroke color for this ImageView. |
| `float` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getStrokeWidth()()` Gets the stroke width for this ImageView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setContentPadding(int,int,int,int)(int left, int top, int right, int bottom)` Set additional padding on the image that is not applied to the background. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setContentPaddingRelative(int,int,int,int)(int start, int top, int end, int bottom)` Set additional relative padding on the image that is not applied to the background. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setPadding(int,int,int,int)(int left, int top, int right, int bottom)` Set the padding. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setPaddingRelative(int,int,int,int)(int start, int top, int end, int bottom)` Set the relative padding. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setShapeAppearanceModel(com.google.android.material.shape.ShapeAppearanceModel)(https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel shapeAppearanceModel)` Sets the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` that defines the shape. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeColor(ColorStateList)(ColorStateList strokeColor)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeColorResource(int)(int strokeColorResourceId)` Sets the stroke color resource for this ImageView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeWidth(float)(float strokeWidth)` Sets the stroke width for this ImageView. |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeWidthResource(int)(int strokeWidthResourceId)` Sets the stroke width dimension resource for this ImageView. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#onDraw(Canvas)(Canvas canvas)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#onMeasure(int,int)(int widthMeasureSpec, int heightMeasureSpec)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#onSizeChanged(int,int,int,int)(int width, int height, int oldWidth, int oldHeight)` |

## Public fields

### shapeAppearanceModel

```
public ShapeAppearanceModel shapeAppearanceModel
```

### strokeColor

```
public ColorStateList strokeColor
```

### strokeWidth

```
public float strokeWidth
```

## Public constructors

### ShapeableImageView

```
public ShapeableImageView(Context context)
```

### ShapeableImageView

```
public ShapeableImageView(Context context, AttributeSet attrs)
```

### ShapeableImageView

```
public ShapeableImageView(Context context, AttributeSet attrs, int defStyle)
```

## Public methods

### getContentPaddingBottom

```
public int getContentPaddingBottom()
```

The additional padding on the bottom of the image, which is not applied to the background.

| Returns |
|---|---|
| `int` | the bottom padding on the image |

### getContentPaddingEnd

```
public final int getContentPaddingEnd()
```

The additional relative padding on the end of the image, which is not applied to the background.

| Returns |
|---|---|
| `int` | the end padding on the image |

### getContentPaddingLeft

```
public int getContentPaddingLeft()
```

The additional padding on the left of the image, which is not applied to the background.

| Returns |
|---|---|
| `int` | the left padding on the image |

### getContentPaddingRight

```
public int getContentPaddingRight()
```

The additional padding on the right of the image, which is not applied to the background.

| Returns |
|---|---|
| `int` | the right padding on the image |

### getContentPaddingStart

```
public final int getContentPaddingStart()
```

The additional relative padding on the start of the image, which is not applied to the background.

| Returns |
|---|---|
| `int` | the start padding on the image |

### getContentPaddingTop

```
public int getContentPaddingTop()
```

The additional padding on the top of the image, which is not applied to the background.

| Returns |
|---|---|
| `int` | the top padding on the image |

### getPaddingBottom

```
public int getPaddingBottom()
```

The padding on the bottom of the View, applied to both the image and the background.

| Returns |
|---|---|
| `int` | the bottom padding |

### getPaddingEnd

```
public int getPaddingEnd()
```

The relative padding on the end of the View, applied to both the image and the background.

| Returns |
|---|---|
| `int` | the end padding |

### getPaddingLeft

```
public int getPaddingLeft()
```

The padding on the left of the View, applied to both the image and the background.

| Returns |
|---|---|
| `int` | the left padding |

### getPaddingRight

```
public int getPaddingRight()
```

The padding on the right of the View, applied to both the image and the background.

| Returns |
|---|---|
| `int` | the right padding |

### getPaddingStart

```
public int getPaddingStart()
```

The relative padding on the start of the View, applied to both the image and the background.

| Returns |
|---|---|
| `int` | the start padding |

### getPaddingTop

```
public int getPaddingTop()
```

The padding on the top of the View, applied to both the image and the background.

| Returns |
|---|---|
| `int` | the top padding |

### getShapeAppearanceModel

```
public ShapeAppearanceModel getShapeAppearanceModel()
```

Returns the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` used for the shape definition.

This `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` can be modified to change the shape.

### getStrokeColor

```
public ColorStateList getStrokeColor()
```

Returns the stroke color for this ImageView.

ref com.google.android.material.R.styleable#ShapeableImageView_strokeColor

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeColor(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeColorResource(int)` |   |

### getStrokeWidth

```
public float getStrokeWidth()
```

Gets the stroke width for this ImageView.

ref com.google.android.material.R.styleable#ShapeableImageView_strokeWidth

| Returns |
|---|---|
| `float` | Stroke width for this ImageView. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeWidth(float)` |   |
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeWidthResource(int)` |   |

### setContentPadding

```
public void setContentPadding(int left, int top, int right, int bottom)
```

Set additional padding on the image that is not applied to the background.

| Parameters |
|---|---|
| `int left` | the padding on the left of the image in pixels |
| `int top` | the padding on the top of the image in pixels |
| `int right` | the padding on the right of the image in pixels |
| `int bottom` | the padding on the bottom of the image in pixels |

### setContentPaddingRelative

```
public void setContentPaddingRelative(int start, int top, int end, int bottom)
```

Set additional relative padding on the image that is not applied to the background.

| Parameters |
|---|---|
| `int start` | the padding on the start of the image in pixels |
| `int top` | the padding on the top of the image in pixels |
| `int end` | the padding on the end of the image in pixels |
| `int bottom` | the padding on the bottom of the image in pixels |

### setPadding

```
public void setPadding(int left, int top, int right, int bottom)
```

Set the padding. This is applied to both the background and the image, and does not affect the content padding differentiating the image from the background.

| Parameters |
|---|---|
| `int left` | the left padding in pixels |
| `int top` | the top padding in pixels |
| `int right` | the right padding in pixels |
| `int bottom` | the bottom padding in pixels |

### setPaddingRelative

```
public void setPaddingRelative(int start, int top, int end, int bottom)
```

Set the relative padding. This is applied to both the background and the image, and does not affect the content padding differentiating the image from the background.

| Parameters |
|---|---|
| `int start` | the start padding in pixels |
| `int top` | the top padding in pixels |
| `int end` | the end padding in pixels |
| `int bottom` | the bottom padding in pixels |

### setShapeAppearanceModel

```
public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)
```

Sets the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` that defines the shape.

### setStrokeColor

```
public void setStrokeColor(ColorStateList strokeColor)
```

### setStrokeColorResource

```
public void setStrokeColorResource(int strokeColorResourceId)
```

Sets the stroke color resource for this ImageView. Both stroke color and stroke width must be set for a stroke to be drawn.

ref com.google.android.material.R.styleable#ShapeableImageView_strokeColor

| Parameters |
|---|---|
| `int strokeColorResourceId` | Color resource to use for the stroke. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeColor(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getStrokeColor()` |   |

### setStrokeWidth

```
public void setStrokeWidth(float strokeWidth)
```

Sets the stroke width for this ImageView. Both stroke color and stroke width must be set for a stroke to be drawn.

ref com.google.android.material.R.styleable#ShapeableImageView_strokeWidth

| Parameters |
|---|---|
| `float strokeWidth` | Stroke width for this ImageView. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeWidthResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getStrokeWidth()` |   |

### setStrokeWidthResource

```
public void setStrokeWidthResource(int strokeWidthResourceId)
```

Sets the stroke width dimension resource for this ImageView. Both stroke color and stroke width must be set for a stroke to be drawn.

ref com.google.android.material.R.styleable#ShapeableImageView_strokeWidth

| Parameters |
|---|---|
| `int strokeWidthResourceId` | Stroke width dimension resource for this ImageView. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#setStrokeWidth(float)` |   |
| `https://developer.android.com/reference/com/google/android/material/imageview/ShapeableImageView#getStrokeWidth()` |   |

## Protected methods

### onDraw

```
protected void onDraw(Canvas canvas)
```

### onMeasure

```
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
```

### onSizeChanged

```
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
```