# FitWidthBitmapDrawable

Artifact: [androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback) [View Source](https://cs.android.com/search?q=file:androidx/leanback/graphics/FitWidthBitmapDrawable.java+class:androidx.leanback.graphics.FitWidthBitmapDrawable) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***


```
public class FitWidthBitmapDrawable extends Drawable
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [android.graphics.drawable.Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) ||
|   | ↳ | [androidx.leanback.graphics.FitWidthBitmapDrawable](https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable) |

*** ** * ** ***

Subclass of `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` 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 `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#draw(android.graphics.Canvas)` call. Top position of the bitmap can be controlled by `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setVerticalOffset(int)` call or `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#PROPERTY_VERTICAL_OFFSET()`.

## Summary

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/android/util/Property.html<https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable, https://developer.android.com/reference/java/lang/Integer.html>` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#PROPERTY_VERTICAL_OFFSET()` Property for `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setVerticalOffset(int)` and `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getVerticalOffset()`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#FitWidthBitmapDrawable()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#draw(android.graphics.Canvas)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Canvas.html canvas)` |
| `int` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getAlpha()()` |
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getBitmap()()` Returns the bitmap. |
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState.html` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getConstantState()()` |
| `int` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getOpacity()()` **This method is deprecated.** |
| `https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getSource()()` Returns the `https://developer.android.com/reference/android/graphics/Rect.html` used for extracting the bitmap. |
| `int` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getVerticalOffset()()` Returns the current vertical offset. |
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#mutate()()` |
| `void` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setAlpha(int)(int alpha)` |
| `void` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setBitmap(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` Sets the bitmap. |
| `void` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setColorFilter(android.graphics.ColorFilter)(https://developer.android.com/reference/android/graphics/ColorFilter.html colorFilter)` |
| `void` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setSource(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html source)` Sets the `https://developer.android.com/reference/android/graphics/Rect.html` used for extracting the bitmap. |
| `void` | `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setVerticalOffset(int)(int offset)` Sets the vertical offset which will be used for drawing the bitmap. |

| ### Inherited methods |
|---|
| From [android.graphics.drawable.Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) |---|---| | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#applyTheme(android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources.Theme.html t)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#canApplyTheme()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#clearColorFilter()()` | | `final https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#copyBounds()()` | | `final void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#copyBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html bounds)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromPath(java.lang.String)(https://developer.android.com/reference/java/lang/String.html pathName)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, java.lang.String)( https://developer.android.com/reference/android/content/res/Resources.html res, https://developer.android.com/reference/android/util/TypedValue.html value, https://developer.android.com/reference/java/io/InputStream.html is, https://developer.android.com/reference/java/lang/String.html srcName )` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromStream(java.io.InputStream, java.lang.String)(https://developer.android.com/reference/java/io/InputStream.html is, https://developer.android.com/reference/java/lang/String.html srcName)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromXml(android.content.res.Resources, org.xmlpull.v1.XmlPullParser)(https://developer.android.com/reference/android/content/res/Resources.html r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html parser)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromXmlInner(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet)( https://developer.android.com/reference/android/content/res/Resources.html r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html parser, https://developer.android.com/reference/android/util/AttributeSet.html attrs )` | | `final https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getBounds()()` | | `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCallback()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getChangingConfigurations()()` | | `https://developer.android.com/reference/android/graphics/ColorFilter.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getColorFilter()()` | | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent()()` | | `https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getDirtyBounds()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getHotspotBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html outRect)` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicWidth()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getLayoutDirection()()` | | `final int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getLevel()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getMinimumHeight()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getMinimumWidth()()` | | `https://developer.android.com/reference/android/graphics/Insets.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getOpticalInsets()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getOutline(android.graphics.Outline)(https://developer.android.com/reference/android/graphics/Outline.html outline)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getPadding(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html padding)` | | `int[]` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getState()()` | | `https://developer.android.com/reference/android/graphics/Region.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getTransparentRegion()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#hasFocusStateSpecified()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#inflate(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet)(https://developer.android.com/reference/android/content/res/Resources.html r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html parser, https://developer.android.com/reference/android/util/AttributeSet.html attrs)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#invalidateSelf()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isAutoMirrored()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isFilterBitmap()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isProjected()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isStateful()()` | | `final boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isVisible()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#jumpToCurrentState()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#onBoundsChange(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html bounds)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#onLayoutDirectionChanged(int)(int layoutDirection)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#onLevelChange(int)(int level)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#onStateChange(int[])(int[] state)` | | `static int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#resolveOpacity(int, int)(int op1, int op2)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#scheduleSelf(java.lang.Runnable, long)(https://developer.android.com/reference/java/lang/Runnable.html what, long when)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setAutoMirrored(boolean)(boolean mirrored)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html bounds)` | | `final void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setCallback(android.graphics.drawable.Drawable.Callback)(https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback.html cb)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setChangingConfigurations(int)(int configs)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setDither(boolean)(boolean dither)` **This method is deprecated.** | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setFilterBitmap(boolean)(boolean filter)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setHotspot(float, float)(float x, float y)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setHotspotBounds(int, int, int, int)(int left, int top, int right, int bottom)` | | `final boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setLayoutDirection(int)(int layoutDirection)` | | `final boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setLevel(int)(int level)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setState(int[])(int[] stateSet)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTint(int)(int tintColor)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTintBlendMode(android.graphics.BlendMode)(https://developer.android.com/reference/android/graphics/BlendMode.html blendMode)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTintList(android.content.res.ColorStateList)(https://developer.android.com/reference/android/content/res/ColorStateList.html tint)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTintMode(android.graphics.PorterDuff.Mode)(https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html tintMode)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setVisible(boolean, boolean)(boolean visible, boolean restart)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#unscheduleSelf(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable.html what)` | |

## Constants

### PROPERTY_VERTICAL_OFFSET

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final Property<FitWidthBitmapDrawable, Integer> PROPERTY_VERTICAL_OFFSET
```

Property for `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#setVerticalOffset(int)` and `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#getVerticalOffset()`.

## Public constructors

### FitWidthBitmapDrawable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public FitWidthBitmapDrawable()
```

## Public methods

### draw

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#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](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public Bitmap getBitmap()
```

Returns the bitmap.

### getConstantState

```
public Drawable.ConstantState getConstantState()
```

### getOpacity

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public int getOpacity()
```

> [!CAUTION]
> **This method is deprecated.**   

### getSource

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public Rect getSource()
```

Returns the `https://developer.android.com/reference/android/graphics/Rect.html` used for extracting the bitmap.

### getVerticalOffset

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public int getVerticalOffset()
```

Returns the current vertical offset.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#PROPERTY_VERTICAL_OFFSET()` |   |

### mutate

```
public Drawable mutate()
```

### setAlpha

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setAlpha(int alpha)
```

### setBitmap

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setBitmap(Bitmap bitmap)
```

Sets the bitmap.

### setColorFilter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setColorFilter(ColorFilter colorFilter)
```

### setSource

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setSource(Rect source)
```

Sets the `https://developer.android.com/reference/android/graphics/Rect.html` used for extracting the bitmap.

### setVerticalOffset

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#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.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/leanback/graphics/FitWidthBitmapDrawable#PROPERTY_VERTICAL_OFFSET()` |   |