Build 1.0_r1(from source)

android.widget
Class ImageView

java.lang.Object
  extended by android.view.View
      extended by android.widget.ImageView
All Implemented Interfaces:
Drawable.Callback, KeyEvent.Callback
Direct Known Subclasses:
ImageButton

public class ImageView
extends View

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.


Nested Class Summary
static class ImageView.ScaleType
          Options for scaling the bounds of an image to the bounds of this view.
 
Nested classes/interfaces inherited from class android.view.View
View.BaseSavedState, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLongClickListener, View.OnTouchListener
 
Field Summary
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIRST_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, INVISIBLE, KEEP_SCREEN_ON, LAST_STATE_SET, mBottom, mContext, mCurrentAnimation, MIDDLE_STATE_SET, mLayoutParams, mLeft, mLocation, mMeasuredHeight, mMeasuredWidth, mOnClickListener, mOnCreateContextMenuListener, mOnFocusChangeListener, mOnLongClickListener, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, NO_ID, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FIRST_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_LAST_STATE_SET, PRESSED_MIDDLE_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_SINGLE_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SINGLE_STATE_SET, SOUND_EFFECTS_ENABLED, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET
 
Constructor Summary
ImageView(Context context)
           
ImageView(Context context, AttributeSet attrs)
           
ImageView(Context context, AttributeSet attrs, int defStyle)
           
 
Method Summary
 void clearColorFilter()
           
protected  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.
 int getBaseline()
          Return the offset of the widget's text baseline from the widget's top boundary.
 Drawable getDrawable()
          Return the view's drawable, or null if no drawable has been assigned.
 Matrix getImageMatrix()
          Return the view's optional matrix.
 ImageView.ScaleType getScaleType()
          Return the current scale type in use by this ImageView.
 void invalidateDrawable(Drawable dr)
          Invalidates the specified Drawable.
 int[] onCreateDrawableState(int extraSpace)
          Generate the new Drawable state for this view.
protected  void onDraw(Canvas canvas)
          Implement this to do your drawing.
protected  void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
           Measure the view and its content to determine the measured width and the measured height.
protected  boolean onSetAlpha(int alpha)
          Invoked if there is a Transform that involves alpha.
 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)
           
 void setColorFilter(ColorFilter cf)
          Apply an arbitrary colorfilter to the image.
 void setColorFilter(int color, PorterDuff.Mode mode)
          Set a tinting option for the image.
protected  boolean setFrame(int l, int t, int r, int b)
          Assign a size and position to this view.
 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 setImageLevel(int level)
           
 void setImageMatrix(Matrix matrix)
           
 void setImageResource(int resId)
          Sets a drawable as the content of this ImageView.
 void setImageState(int[] state, boolean merge)
           
 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  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.
 
Methods inherited from class android.view.View
addFocusables, addTouchables, applyDrawableToTransparentRegion, bringToFront, buildDrawingCache, cancelLongPress, clearAnimation, clearFocus, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, debug, debug, debugIndent, destroyDrawingCache, dispatchDraw, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, draw, finalize, findFocus, findViewById, findViewTraversal, findViewWithTag, findViewWithTagTraversal, fitSystemWindows, focusSearch, forceLayout, gatherTransparentRegion, getAnimation, getApplicationWindowToken, getBackground, getBottom, getBottomFadingEdgeStrength, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRightFadingEdgeStrength, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTop, getTopFadingEdgeStrength, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, hasFocus, hasFocusable, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInTouchMode, isLayoutRequested, isLongClickable, isPressed, isRootNamespace, isSaveEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onAttachedToWindow, onCreateContextMenu, onDetachedFromWindow, onFinishInflate, onFocusChanged, onKeyDown, onKeyMultiple, onKeyShortcut, onKeyUp, onLayout, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSizeChanged, onTouchEvent, onTrackballEvent, onWindowFocusChanged, onWindowVisibilityChanged, performClick, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setIsRootNamespace, setKeepScreenOn, setLayoutParams, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnTouchListener, setPadding, setPressed, setSaveEnabled, setScrollBarStyle, setSoundEffectsEnabled, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVisibility, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageView

public ImageView(Context context)

ImageView

public ImageView(Context context,
                 AttributeSet attrs)

ImageView

public ImageView(Context context,
                 AttributeSet attrs,
                 int defStyle)
Method Detail

verifyDrawable

protected boolean verifyDrawable(Drawable dr)
Description copied from class: View
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.

Overrides:
verifyDrawable in class View
Parameters:
dr - 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 If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.
See Also:
View.unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable), View.drawableStateChanged()

invalidateDrawable

public void invalidateDrawable(Drawable dr)
Description copied from class: View
Invalidates the specified Drawable.

Specified by:
invalidateDrawable in interface Drawable.Callback
Overrides:
invalidateDrawable in class View
Parameters:
dr - the drawable to invalidate

onSetAlpha

protected boolean onSetAlpha(int alpha)
Description copied from class: View
Invoked if there is a Transform that involves alpha. Subclass that can draw themselves with the specified alpha should return true, and then respect that alpha when their onDraw() is called. If this returns false then the view may be redirected to draw into an offscreen buffer to fulfill the request, which will look fine, but may be slower than if the subclass handles it internally. The default implementation returns false.

Overrides:
onSetAlpha in class View
Parameters:
alpha - The alpha (0..255) to apply to the view's drawing
Returns:
true if the view can draw with the specified alpha.

setAdjustViewBounds

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

Parameters:
adjustViewBounds - Whether to adjust the bounds of this view to presrve the original aspect ratio of the drawable

setMaxWidth

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

Parameters:
maxWidth - maximum width for this view

setMaxHeight

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

Parameters:
maxHeight - maximum height for this view

getDrawable

public Drawable getDrawable()
Return the view's drawable, or null if no drawable has been assigned.


setImageResource

public void setImageResource(int resId)
Sets a drawable as the content of this ImageView.

Parameters:
resId - the resource identifier of the the drawable

setImageURI

public void setImageURI(Uri uri)
Sets the content of this ImageView to the specified Uri.

Parameters:
uri - The Uri of an image

setImageDrawable

public void setImageDrawable(Drawable drawable)
Sets a drawable as the content of this ImageView.

Parameters:
drawable - The drawable to set

setImageBitmap

public void setImageBitmap(Bitmap bm)
Sets a Bitmap as the content of this ImageView.

Parameters:
bm - The bitmap to set

setImageState

public void setImageState(int[] state,
                          boolean merge)

setSelected

public void setSelected(boolean selected)
Description copied from class: View
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.

Overrides:
setSelected in class View
Parameters:
selected - true if the view must be selected, false otherwise

setImageLevel

public void setImageLevel(int level)

setScaleType

public void setScaleType(ImageView.ScaleType scaleType)
Controls how the image should be resized or moved to match the size of this ImageView.

Parameters:
scaleType - The desired scaling mode.

getScaleType

public ImageView.ScaleType getScaleType()
Return the current scale type in use by this ImageView.

See Also:
ImageView.ScaleType

getImageMatrix

public Matrix getImageMatrix()
Return the view's optional matrix. This is applied to the view's drawable when it is drawn. If there is not matrix, this method will return null. Do not change this matrix in place. If you want a different matrix applied to the drawable, be sure to call setImageMatrix().


setImageMatrix

public void setImageMatrix(Matrix matrix)

onCreateDrawableState

public int[] onCreateDrawableState(int extraSpace)
Description copied from class: View
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 View.getDrawableState().

Overrides:
onCreateDrawableState in class View
Parameters:
extraSpace - 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:
Returns an array holding the current Drawable state of the view.
See Also:
View.mergeDrawableStates(int[], int[])

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)
Description copied from class: View

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

CONTRACT: When overriding this method, you must call View.setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by View.measure(int, int). Calling the superclass' View.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 View.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 (View.getSuggestedMinimumHeight() and View.getSuggestedMinimumWidth()).

Overrides:
onMeasure in class View
Parameters:
widthMeasureSpec - horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec - vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
See Also:
View.getMeasuredWidth(), View.getMeasuredHeight(), View.setMeasuredDimension(int, int), View.getSuggestedMinimumHeight(), View.getSuggestedMinimumWidth(), View.MeasureSpec.getMode(int), View.MeasureSpec.getSize(int)

setFrame

protected boolean setFrame(int l,
                           int t,
                           int r,
                           int b)
Description copied from class: View
Assign a size and position to this view. This is called from layout.

Overrides:
setFrame in class View
Parameters:
l - Left position, relative to parent
t - Top position, relative to parent
r - Right position, relative to parent
b - Bottom position, relative to parent
Returns:
true if the new size and position are different than the previous ones

drawableStateChanged

protected void drawableStateChanged()
Description copied from class: View
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

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

Overrides:
drawableStateChanged in class View
See Also:
Drawable.setState(int[])

onDraw

protected void onDraw(Canvas canvas)
Description copied from class: View
Implement this to do your drawing.

Overrides:
onDraw in class View
Parameters:
canvas - the canvas on which the background will be drawn

getBaseline

public int getBaseline()
Description copied from class: View

Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.

Overrides:
getBaseline in class View
Returns:
the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

setColorFilter

public final void setColorFilter(int color,
                                 PorterDuff.Mode mode)
Set a tinting option for the image.

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

clearColorFilter

public final void clearColorFilter()

setColorFilter

public void setColorFilter(ColorFilter cf)
Apply an arbitrary colorfilter to the image.

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

setAlpha

public void setAlpha(int alpha)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature