Most visited

Recently visited

Added in API level 1

ImageView

public class ImageView
extends View

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
Known Direct Subclasses
Known Indirect Subclasses


Displays an arbitrary image, such as an icon. The ImageView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the image so that it can be used in any layout manager, and provides various display options such as scaling and tinting.

Summary

Nested classes

enum ImageView.ScaleType

Options for scaling the bounds of an image to the bounds of this view. 

XML attributes

android:adjustViewBounds Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable. 
android:baseline The offset of the baseline within this view. 
android:baselineAlignBottom If true, the image view will be baseline aligned with based on its bottom edge. 
android:cropToPadding If true, the image will be cropped to fit within its padding. 
android:maxHeight An optional argument to supply a maximum height for this view. 
android:maxWidth An optional argument to supply a maximum width for this view. 
android:scaleType Controls how the image should be resized or moved to match the size of this ImageView. 
android:src Sets a drawable as the content of this ImageView. 
android:tint Set a tinting color for the image. 
android:tintMode Blending mode used to apply the image tint. 

Inherited XML attributes

From class android.view.View

Inherited constants

From class android.view.View

Inherited fields

From class android.view.View

Public constructors

ImageView(Context context)
ImageView(Context context, AttributeSet attrs)
ImageView(Context context, AttributeSet attrs, int defStyleAttr)
ImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

final void clearColorFilter()
void drawableHotspotChanged(float x, float y)

This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

boolean getAdjustViewBounds()

True when ImageView is adjusting its bounds to preserve the aspect ratio of its drawable

int getBaseline()

Return the offset of the widget's text baseline from the widget's top boundary.

boolean getBaselineAlignBottom()

Return whether this view's baseline will be considered the bottom of the view.

ColorFilter getColorFilter()

Returns the active color filter for this ImageView.

boolean getCropToPadding()

Return whether this ImageView crops to padding.

Drawable getDrawable()

Return the view's drawable, or null if no drawable has been assigned.

int getImageAlpha()

Returns the alpha that will be applied to the drawable of this ImageView.

Matrix getImageMatrix()

Return the view's optional matrix.

ColorStateList getImageTintList()
PorterDuff.Mode getImageTintMode()
int getMaxHeight()

The maximum height of this view.

int getMaxWidth()

The maximum width of this view.

ImageView.ScaleType getScaleType()

Return the current scale type in use by this ImageView.

boolean hasOverlappingRendering()

Returns whether this View has content which overlaps.

void invalidateDrawable(Drawable dr)

Invalidates the specified Drawable.

boolean isOpaque()

Indicates whether this View is opaque.

void jumpDrawablesToCurrentState()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

int[] onCreateDrawableState(int extraSpace)

Generate the new Drawable state for this view.

void onRtlPropertiesChanged(int layoutDirection)

Called when any RTL property (layout direction or text direction or text alignment) has been changed.

void onVisibilityAggregated(boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancestor view or the window this view is attached to.

void setAdjustViewBounds(boolean adjustViewBounds)

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

void setAlpha(int alpha)

This method was deprecated in API level 16. use #setImageAlpha(int) instead

void setBaseline(int baseline)

Set the offset of the widget's text baseline from the widget's top boundary.

void setBaselineAlignBottom(boolean aligned)

Set whether to set the baseline of this view to the bottom of the view.

final void setColorFilter(int color, PorterDuff.Mode mode)

Set a tinting option for the image.

void setColorFilter(ColorFilter cf)

Apply an arbitrary colorfilter to the image.

final void setColorFilter(int color)

Set a tinting option for the image.

void setCropToPadding(boolean cropToPadding)

Sets whether this ImageView will crop to padding.

void setImageAlpha(int alpha)

Sets the alpha value that should be applied to the image.

void setImageBitmap(Bitmap bm)

Sets a Bitmap as the content of this ImageView.

void setImageDrawable(Drawable drawable)

Sets a drawable as the content of this ImageView.

void setImageIcon(Icon icon)

Sets the content of this ImageView to the specified Icon.

void setImageLevel(int level)

Sets the image level, when it is constructed from a LevelListDrawable.

void setImageMatrix(Matrix matrix)

Adds a transformation Matrix that is applied to the view's drawable when it is drawn.

void setImageResource(int resId)

Sets a drawable as the content of this ImageView.

void setImageState(int[] state, boolean merge)
void setImageTintList(ColorStateList tint)

Applies a tint to the image drawable.

void setImageTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setImageTintList(ColorStateList)} to the image drawable.

void setImageURI(Uri uri)

Sets the content of this ImageView to the specified Uri.

void setMaxHeight(int maxHeight)

An optional argument to supply a maximum height for this view.

void setMaxWidth(int maxWidth)

An optional argument to supply a maximum width for this view.

void setScaleType(ImageView.ScaleType scaleType)

Controls how the image should be resized or moved to match the size of this ImageView.

void setSelected(boolean selected)

Changes the selection state of this view.

Protected methods

void drawableStateChanged()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

void onDraw(Canvas canvas)

Implement this to do your drawing.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

boolean setFrame(int l, int t, int r, int b)

Assign a size and position to this view.

boolean verifyDrawable(Drawable dr)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

Inherited methods

From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML attributes

android:adjustViewBounds

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol adjustViewBounds.

Related methods:

android:baseline

The offset of the baseline within this view. See {see android.view.View#getBaseline} for details

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol baseline.

Related methods:

android:baselineAlignBottom

If true, the image view will be baseline aligned with based on its bottom edge.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol baselineAlignBottom.

Related methods:

android:cropToPadding

If true, the image will be cropped to fit within its padding.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol cropToPadding.

Related methods:

android:maxHeight

An optional argument to supply a maximum height for this view. See {see android.widget.ImageView#setMaxHeight} for details.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxHeight.

Related methods:

android:maxWidth

An optional argument to supply a maximum width for this view. See {see android.widget.ImageView#setMaxWidth} for details.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol maxWidth.

Related methods:

android:scaleType

Controls how the image should be resized or moved to match the size of this ImageView. See ImageView.ScaleType

Must be one of the following constant values.

ConstantValueDescription
matrix0 Scale using the image matrix when drawing. See setImageMatrix(Matrix).
fitXY1 Scale the image using FILL.
fitStart2 Scale the image using START.
fitCenter3 Scale the image using CENTER.
fitEnd4 Scale the image using END.
center5 Center the image in the view, but perform no scaling.
centerCrop6 Scale the image uniformly (maintain the image's aspect ratio) so both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). The image is then centered in the view.
centerInside7 Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). The image is then centered in the view.

This corresponds to the global attribute resource symbol scaleType.

Related methods:

android:src

Sets a drawable as the content of this ImageView.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This corresponds to the global attribute resource symbol src.

Related methods:

android:tint

Set a tinting color for the image. By default, the tint will blend using SRC_ATOP mode.

Must be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol tint.

Related methods:

android:tintMode

Blending mode used to apply the image tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol tintMode.

Related methods:

Public constructors

ImageView

Added in API level 1
ImageView (Context context)

Parameters
context Context

ImageView

Added in API level 1
ImageView (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

ImageView

Added in API level 1
ImageView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

ImageView

Added in API level 21
ImageView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public methods

clearColorFilter

Added in API level 1
void clearColorFilter ()

drawableHotspotChanged

Added in API level 21
void drawableHotspotChanged (float x, 
                float y)

This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.

Dispatching to child views is handled by dispatchDrawableHotspotChanged(float, float).

Be sure to call through to the superclass when overriding this function.

Parameters
x float: hotspot x coordinate
y float: hotspot y coordinate

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getAdjustViewBounds

Added in API level 16
boolean getAdjustViewBounds ()

True when ImageView is adjusting its bounds to preserve the aspect ratio of its drawable

Related XML Attributes:

Returns
boolean whether to adjust the bounds of this view to preserve the original aspect ratio of the drawable

See also:

getBaseline

Added in API level 1
int getBaseline ()

Return the offset of the widget's text baseline from the widget's top boundary.

Returns
int the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported.

getBaselineAlignBottom

Added in API level 11
boolean getBaselineAlignBottom ()

Return whether this view's baseline will be considered the bottom of the view.

Returns
boolean

See also:

getColorFilter

Added in API level 16
ColorFilter getColorFilter ()

Returns the active color filter for this ImageView.

Returns
ColorFilter the active color filter for this ImageView

See also:

getCropToPadding

Added in API level 16
boolean getCropToPadding ()

Return whether this ImageView crops to padding.

Related XML Attributes:

Returns
boolean whether this ImageView crops to padding

See also:

getDrawable

Added in API level 1
Drawable getDrawable ()

Return the view's drawable, or null if no drawable has been assigned.

Returns
Drawable

getImageAlpha

Added in API level 16
int getImageAlpha ()

Returns the alpha that will be applied to the drawable of this ImageView.

Returns
int the alpha that will be applied to the drawable of this ImageView

See also:

getImageMatrix

Added in API level 1
Matrix getImageMatrix ()

Return the view's optional matrix. This is applied to the view's drawable when it is drawn. If there is no matrix, this method will return an identity matrix. Do not change this matrix in place but make a copy. If you want a different matrix applied to the drawable, be sure to call setImageMatrix().

Returns
Matrix

getImageTintList

Added in API level 21
ColorStateList getImageTintList ()

Related XML Attributes:

Returns
ColorStateList the tint applied to the image drawable

See also:

getImageTintMode

Added in API level 21
PorterDuff.Mode getImageTintMode ()

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the image drawable

See also:

getMaxHeight

Added in API level 16
int getMaxHeight ()

The maximum height of this view.

Related XML Attributes:

Returns
int The maximum height of this view

See also:

getMaxWidth

Added in API level 16
int getMaxWidth ()

The maximum width of this view.

Related XML Attributes:

Returns
int The maximum width of this view

See also:

getScaleType

Added in API level 1
ImageView.ScaleType getScaleType ()

Return the current scale type in use by this ImageView.

Related XML Attributes:

Returns
ImageView.ScaleType

See also:

hasOverlappingRendering

Added in API level 16
boolean hasOverlappingRendering ()

Returns whether this View has content which overlaps.

This function, intended to be overridden by specific View types, is an optimization when alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer and then composited into place, which can be expensive. If the view has no overlapping rendering, the view can draw each primitive with the appropriate alpha value directly. An example of overlapping rendering is a TextView with a background image, such as a Button. An example of non-overlapping rendering is a TextView with no background, or an ImageView with only the foreground image. The default implementation returns true; subclasses should override if they have cases which can be optimized.

The current implementation of the saveLayer and saveLayerAlpha methods in Canvas necessitates that a View return true if it uses the methods internally without passing the CLIP_TO_LAYER_SAVE_FLAG.

Note: The return value of this method is ignored if forceHasOverlappingRendering(boolean) has been called on this view.

Returns
boolean true if the content in this view might overlap, false otherwise.

invalidateDrawable

Added in API level 1
void invalidateDrawable (Drawable dr)

Invalidates the specified Drawable.

Parameters
dr Drawable: the drawable to invalidate

isOpaque

Added in API level 7
boolean isOpaque ()

Indicates whether this View is opaque. An opaque View guarantees that it will draw all the pixels overlapping its bounds using a fully opaque color. Subclasses of View should override this method whenever possible to indicate whether an instance is opaque. Opaque Views are treated in a special way by the View hierarchy, possibly allowing it to perform optimizations during invalidate/draw passes.

Returns
boolean True if this View is guaranteed to be fully opaque, false otherwise.

jumpDrawablesToCurrentState

Added in API level 11
void jumpDrawablesToCurrentState ()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

Also calls jumpToCurrentState() if there is a StateListAnimator attached to this view.

onCreateDrawableState

Added in API level 1
int[] onCreateDrawableState (int extraSpace)

Generate the new Drawable state for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should use getDrawableState().

Parameters
extraSpace int: if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.
Returns
int[] Returns an array holding the current Drawable state of the view.

onRtlPropertiesChanged

Added in API level 17
void onRtlPropertiesChanged (int layoutDirection)

Called when any RTL property (layout direction or text direction or text alignment) has been changed. Subclasses need to override this method to take care of cached information that depends on the resolved layout direction, or to inform child views that inherit their layout direction. The default implementation does nothing.

Parameters
layoutDirection int: the direction of the layout

onVisibilityAggregated

Added in API level 24
void onVisibilityAggregated (boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancestor view or the window this view is attached to.

Parameters
isVisible boolean: true if this view and all of its ancestors are VISIBLE and this view's window is also visible

setAdjustViewBounds

Added in API level 1
void setAdjustViewBounds (boolean adjustViewBounds)

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

Note: If the application targets API level 17 or lower, adjustViewBounds will allow the drawable to shrink the view bounds, but not grow to fill available measured space in all cases. This is for compatibility with legacy MeasureSpec and RelativeLayout behavior.

Related XML Attributes:

Parameters
adjustViewBounds boolean: Whether to adjust the bounds of this view to preserve the original aspect ratio of the drawable.

See also:

setAlpha

Added in API level 1
void setAlpha (int alpha)

This method was deprecated in API level 16.
use #setImageAlpha(int) instead

Sets the alpha value that should be applied to the image.

Parameters
alpha int: the alpha value that should be applied to the image

setBaseline

Added in API level 11
void setBaseline (int baseline)

Set the offset of the widget's text baseline from the widget's top boundary. This value is overridden by the setBaselineAlignBottom(boolean) property.

Related XML Attributes:

Parameters
baseline int: The baseline to use, or -1 if none is to be provided.

See also:

setBaselineAlignBottom

Added in API level 11
void setBaselineAlignBottom (boolean aligned)

Set whether to set the baseline of this view to the bottom of the view. Setting this value overrides any calls to setBaseline.

Related XML Attributes:

Parameters
aligned boolean: If true, the image view will be baseline aligned with based on its bottom edge.

setColorFilter

Added in API level 1
void setColorFilter (int color, 
                PorterDuff.Mode mode)

Set a tinting option for the image.

Related XML Attributes:

Parameters
color int: Color tint to apply.
mode PorterDuff.Mode: How to apply the color. The standard mode is SRC_ATOP

setColorFilter

Added in API level 1
void setColorFilter (ColorFilter cf)

Apply an arbitrary colorfilter to the image.

Parameters
cf ColorFilter: the colorfilter to apply (may be null)

See also:

setColorFilter

Added in API level 8
void setColorFilter (int color)

Set a tinting option for the image. Assumes SRC_ATOP blending mode.

Related XML Attributes:

Parameters
color int: Color tint to apply.

setCropToPadding

Added in API level 16
void setCropToPadding (boolean cropToPadding)

Sets whether this ImageView will crop to padding.

Related XML Attributes:

Parameters
cropToPadding boolean: whether this ImageView will crop to padding

See also:

setImageAlpha

Added in API level 16
void setImageAlpha (int alpha)

Sets the alpha value that should be applied to the image.

Parameters
alpha int: the alpha value that should be applied to the image

See also:

setImageBitmap

Added in API level 1
void setImageBitmap (Bitmap bm)

Sets a Bitmap as the content of this ImageView.

Parameters
bm Bitmap: The bitmap to set

setImageDrawable

Added in API level 1
void setImageDrawable (Drawable drawable)

Sets a drawable as the content of this ImageView.

Parameters
drawable Drawable: the Drawable to set, or null to clear the content

setImageIcon

Added in API level 23
void setImageIcon (Icon icon)

Sets the content of this ImageView to the specified Icon.

Depending on the Icon type, this may do Bitmap reading and decoding on the UI thread, which can cause UI jank. If that's a concern, consider using loadDrawableAsync(Context, Icon.OnDrawableLoadedListener, Handler) and then setImageDrawable(android.graphics.drawable.Drawable) instead.

Parameters
icon Icon: an Icon holding the desired image, or null to clear the content

setImageLevel

Added in API level 1
void setImageLevel (int level)

Sets the image level, when it is constructed from a LevelListDrawable.

Parameters
level int: The new level for the image.

setImageMatrix

Added in API level 1
void setImageMatrix (Matrix matrix)

Adds a transformation Matrix that is applied to the view's drawable when it is drawn. Allows custom scaling, translation, and perspective distortion.

Parameters
matrix Matrix: the transformation parameters in matrix form

setImageResource

Added in API level 1
void setImageResource (int resId)

Sets a drawable as the content of this ImageView.

This does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup. If that's a concern, consider using setImageDrawable(android.graphics.drawable.Drawable) or setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead.

Related XML Attributes:

Parameters
resId int: the resource identifier of the drawable

setImageState

Added in API level 1
void setImageState (int[] state, 
                boolean merge)

Parameters
state int
merge boolean

setImageTintList

Added in API level 21
void setImageTintList (ColorStateList tint)

Applies a tint to the image drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to setImageDrawable(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

See also:

setImageTintMode

Added in API level 21
void setImageTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setImageTintList(ColorStateList)} to the image drawable. The default mode is SRC_IN.

Related XML Attributes:

Parameters
tintMode PorterDuff.Mode: the blending mode used to apply the tint, may be null to clear tint

See also:

setImageURI

Added in API level 1
void setImageURI (Uri uri)

Sets the content of this ImageView to the specified Uri.

This does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup. If that's a concern, consider using setImageDrawable(Drawable) or setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead.

Parameters
uri Uri: the Uri of an image, or null to clear the content

setMaxHeight

Added in API level 1
void setMaxHeight (int maxHeight)

An optional argument to supply a maximum height for this view. Only valid if setAdjustViewBounds(boolean) has been set to true. To set an image to be a maximum of 100 x 100 while preserving the original aspect ratio, do the following: 1) set adjustViewBounds to true 2) set maxWidth and maxHeight to 100 3) set the height and width layout params to WRAP_CONTENT.

Note that this view could be still smaller than 100 x 100 using this approach if the original image is small. To set an image to a fixed size, specify that size in the layout params and then use setScaleType(android.widget.ImageView.ScaleType) to determine how to fit the image within the bounds.

Related XML Attributes:

Parameters
maxHeight int: maximum height for this view

See also:

setMaxWidth

Added in API level 1
void setMaxWidth (int maxWidth)

An optional argument to supply a maximum width for this view. Only valid if setAdjustViewBounds(boolean) has been set to true. To set an image to be a maximum of 100 x 100 while preserving the original aspect ratio, do the following: 1) set adjustViewBounds to true 2) set maxWidth and maxHeight to 100 3) set the height and width layout params to WRAP_CONTENT.

Note that this view could be still smaller than 100 x 100 using this approach if the original image is small. To set an image to a fixed size, specify that size in the layout params and then use setScaleType(android.widget.ImageView.ScaleType) to determine how to fit the image within the bounds.

Related XML Attributes:

Parameters
maxWidth int: maximum width for this view

See also:

setScaleType

Added in API level 1
void setScaleType (ImageView.ScaleType scaleType)

Controls how the image should be resized or moved to match the size of this ImageView.

Related XML Attributes:

Parameters
scaleType ImageView.ScaleType: The desired scaling mode.

setSelected

Added in API level 1
void setSelected (boolean selected)

Changes the selection state of this view. A view can be selected or not. Note that selection is not the same as focus. Views are typically selected in the context of an AdapterView like ListView or GridView; the selected view is the view that is highlighted.

Parameters
selected boolean: true if the view must be selected, false otherwise

Protected methods

drawableStateChanged

Added in API level 1
void drawableStateChanged ()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

onDraw

Added in API level 1
void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters
canvas Canvas: the canvas on which the background will be drawn

onMeasure

Added in API level 1
void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

setFrame

Added in API level 1
boolean setFrame (int l, 
                int t, 
                int r, 
                int b)

Assign a size and position to this view. This is called from layout.

Parameters
l int: Left position, relative to parent
t int: Top position, relative to parent
r int: Right position, relative to parent
b int: Bottom position, relative to parent
Returns
boolean true if the new size and position are different than the previous ones

verifyDrawable

Added in API level 1
boolean verifyDrawable (Drawable dr)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
dr Drawable: The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns
boolean boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.

Hooray!