ShapeableImageView

public class ShapeableImageView implements Shapeable


An ImageView that draws the bitmap with the provided Shape.

Summary

Public constructors

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

Public methods

int

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

final int

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

int

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

int

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

final int

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

int

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

int

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

int

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

int

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

int

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

int

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

int

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

ShapeAppearanceModel

Returns the ShapeAppearanceModel used for the shape definition.

ColorStateList

Returns the stroke color for this ImageView.

float

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

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)

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

This 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

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.

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 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.

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.

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.

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)