ShapeableImageView

public class ShapeableImageView
extends AppCompatImageView implements Shapeable

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ androidx.appcompat.widget.AppCompatImageView
         ↳ com.google.android.material.imageview.ShapeableImageView


An ImageView that draws the bitmap with the provided Shape.

Summary

XML attributes

ShapeableImageView_strokeColor  
ShapeableImageView_strokeWidth  

Inherited constants

Inherited fields

Public constructors

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

Public methods

int getContentPaddingBottom()

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

final int getContentPaddingEnd()

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

int getContentPaddingLeft()

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

int getContentPaddingRight()

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

final int getContentPaddingStart()

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

int getContentPaddingTop()

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

int getPaddingBottom()

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

int getPaddingEnd()

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

int getPaddingLeft()

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

int getPaddingRight()

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

int getPaddingStart()

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

int getPaddingTop()

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

ShapeAppearanceModel getShapeAppearanceModel()

Returns the ShapeAppearanceModel used for the shape definition.

ColorStateList getStrokeColor()

Returns the stroke color for this ImageView.

float getStrokeWidth()

Gets the stroke width for this ImageView.

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

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

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

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

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

Set the padding.

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

Set the relative padding.

void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the shape.

void setStrokeColor(ColorStateList strokeColor)
void setStrokeColorResource(int strokeColorResourceId)

Sets the stroke color resource for this ImageView.

void setStrokeWidth(float strokeWidth)

Sets the stroke width for this ImageView.

void setStrokeWidthResource(int strokeWidthResourceId)

Sets the stroke width dimension resource for this ImageView.

Protected methods

void onDraw(Canvas canvas)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onSizeChanged(int width, int height, int oldWidth, int oldHeight)

Inherited methods

XML attributes

ShapeableImageView_strokeColor

Related methods:

ShapeableImageView_strokeWidth

Related methods:

Public constructors

ShapeableImageView

public ShapeableImageView (Context context)

Parameters
context Context

ShapeableImageView

public ShapeableImageView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

ShapeableImageView

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

Parameters
context Context

attrs AttributeSet

defStyle int

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 ShapeAppearanceModel used for the shape definition.

This ShapeAppearanceModel can be modified to change the shape.

Returns
ShapeAppearanceModel

getStrokeColor

public ColorStateList getStrokeColor ()

Returns the stroke color for this ImageView.

Related XML Attributes:

Returns
ColorStateList

getStrokeWidth

public float getStrokeWidth ()

Gets the stroke width for this ImageView.

Related XML Attributes:

Returns
float Stroke width for this ImageView.

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
left int: the padding on the left of the image in pixels

top int: the padding on the top of the image in pixels

right int: the padding on the right of the image in pixels

bottom int: 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
start int: the padding on the start of the image in pixels

top int: the padding on the top of the image in pixels

end int: the padding on the end of the image in pixels

bottom int: 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
left int: the left padding in pixels

top int: the top padding in pixels

right int: the right padding in pixels

bottom int: 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
start int: the start padding in pixels

top int: the top padding in pixels

end int: the end padding in pixels

bottom int: the bottom padding in pixels

setShapeAppearanceModel

public void setShapeAppearanceModel (ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the shape.

Parameters
shapeAppearanceModel ShapeAppearanceModel

setStrokeColor

public void setStrokeColor (ColorStateList strokeColor)

Parameters
strokeColor ColorStateList

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.

Related XML Attributes:

Parameters
strokeColorResourceId int: Color resource to use for the stroke.

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.

Related XML Attributes:

Parameters
strokeWidth float: Stroke width for this ImageView.

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.

Related XML Attributes:

Parameters
strokeWidthResourceId int: Stroke width dimension resource for this ImageView.

Protected methods

onDraw

protected void onDraw (Canvas canvas)

Parameters
canvas Canvas

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onSizeChanged

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

Parameters
width int

height int

oldWidth int

oldHeight int