FitWidthBitmapDrawable

public class FitWidthBitmapDrawable extends Drawable


Subclass of Drawable that can be used to draw a bitmap into a region. Bitmap will be scaled to fit the full width of the region and will be aligned to the top left corner. Any region outside the bounds will be clipped during draw call. Top position of the bitmap can be controlled by setVerticalOffset call or PROPERTY_VERTICAL_OFFSET.

Summary

Public constructors

Public methods

void
draw(@NonNull Canvas canvas)
int
Bitmap

Returns the bitmap.

Drawable.ConstantState
int

This method is deprecated.

Rect

Returns the Rect used for extracting the bitmap.

int

Returns the current vertical offset.

Drawable
void
setAlpha(int alpha)
void
setBitmap(Bitmap bitmap)

Sets the bitmap.

void
void
setSource(Rect source)

Sets the Rect used for extracting the bitmap.

void
setVerticalOffset(int offset)

Sets the vertical offset which will be used for drawing the bitmap.

Inherited methods

From android.graphics.drawable.Drawable
void
boolean
void
final Rect
final void
copyBounds(Rect bounds)
static Drawable
static Drawable
createFromResourceStream(
    Resources res,
    TypedValue value,
    InputStream is,
    String srcName
)
static Drawable
static Drawable
static Drawable
createFromXmlInner(
    Resources r,
    XmlPullParser parser,
    AttributeSet attrs
)
final Rect
Drawable.Callback
int
ColorFilter
Drawable
Rect
void
int
int
int
final int
int
int
Insets
void
boolean
getPadding(Rect padding)
int[]
Region
boolean
void
void
boolean
boolean
boolean
boolean
final boolean
void
void
boolean
onLayoutDirectionChanged(int layoutDirection)
boolean
onLevelChange(int level)
boolean
onStateChange(int[] state)
static int
resolveOpacity(int op1, int op2)
void
scheduleSelf(Runnable what, long when)
void
setAutoMirrored(boolean mirrored)
void
setBounds(int left, int top, int right, int bottom)
final void
void
void
setDither(boolean dither)

This method is deprecated.

void
setFilterBitmap(boolean filter)
void
setHotspot(float x, float y)
void
setHotspotBounds(int left, int top, int right, int bottom)
final boolean
setLayoutDirection(int layoutDirection)
final boolean
setLevel(int level)
boolean
setState(int[] stateSet)
void
setTint(int tintColor)
void
void
void
boolean
setVisible(boolean visible, boolean restart)
void

Constants

PROPERTY_VERTICAL_OFFSET

Added in 1.1.0
public static final Property<FitWidthBitmapDrawableIntegerPROPERTY_VERTICAL_OFFSET

Property for setVerticalOffset and getVerticalOffset.

Public constructors

FitWidthBitmapDrawable

Added in 1.1.0
public FitWidthBitmapDrawable()

Public methods

draw

Added in 1.1.0
public void draw(@NonNull Canvas canvas)

getAlpha

public int getAlpha()
Returns
int

Alpha value between 0(inclusive) and 255(inclusive)

getBitmap

Added in 1.1.0
public Bitmap getBitmap()

Returns the bitmap.

getConstantState

public Drawable.ConstantState getConstantState()

getOpacity

Added in 1.1.0
public int getOpacity()

getSource

Added in 1.1.0
public Rect getSource()

Returns the Rect used for extracting the bitmap.

getVerticalOffset

Added in 1.1.0
public int getVerticalOffset()

Returns the current vertical offset.

mutate

public Drawable mutate()

setAlpha

Added in 1.1.0
public void setAlpha(int alpha)

setBitmap

Added in 1.1.0
public void setBitmap(Bitmap bitmap)

Sets the bitmap.

setColorFilter

Added in 1.1.0
public void setColorFilter(ColorFilter colorFilter)

setSource

Added in 1.1.0
public void setSource(Rect source)

Sets the Rect used for extracting the bitmap.

setVerticalOffset

Added in 1.1.0
public void setVerticalOffset(int offset)

Sets the vertical offset which will be used for drawing the bitmap. The bitmap drawing will start the provided vertical offset.