Class ImageView
- All Implemented Interfaces:
Drawable.Callback
- Direct Known Subclasses:
ImageButton
Image
or Drawable
resources.
ImageView is also commonly used to
apply tints to an image and
handle image scaling.
To learn more about Drawables, see: Drawable Resources.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Options for scaling the bounds of an image to the bounds of this view.Nested classes/interfaces inherited from class icyllis.modernui.view.View
View.DragShadow, View.Focusable, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.NestedScrollType, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollAxis, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility
-
Field Summary
Fields inherited from class icyllis.modernui.view.View
ALPHA, BOTTOM, 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, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLE, FOCUSABLE_AUTO, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, LEFT, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mScrollX, mScrollY, NO_ID, NOT_FOCUSABLE, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, 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_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, RIGHT, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLL_X, SCROLL_Y, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TOP, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, TYPE_NON_TOUCH, TYPE_TOUCH, VIEW_MARKER, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
animateTransform
(Matrix matrix) Applies a temporary transformationMatrix
to the view's drawable when it is drawn.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.protected void
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.boolean
True when ImageView is adjusting its bounds to preserve the aspect ratio of its drawableint
Return the offset of the widget's text baseline from the widget's top boundary.boolean
Checks whether this view's baseline is considered the bottom of the view.Returns the active color filter for this ImageView.boolean
Return whether this ImageView crops to padding.Gets the current Drawable, or null if no Drawable has been assigned.int
Returns the alpha that will be applied to the drawable of this ImageView.Returns the view's optional matrix.Gets the blending mode used to apply the tint to the image DrawableGet the currentColorStateList
used to tint the image Drawable, or null if no tint is applied.int
The maximum height of this view.int
The maximum width of this view.Returns the current ScaleType that is used to scale the bounds of an image to the bounds of the ImageView.boolean
Returns whether this View has content which overlaps.void
Invalidates the specified Drawable.void
CallDrawable.jumpToCurrentState()
on all Drawable objects associated with this view.int[]
onCreateDrawableState
(int extraSpace) Generate the newDrawable
state for this view.protected void
Draw the content of this view, 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.void
onRtlPropertiesChanged
(int layoutDirection) Called when any RTL property (layout direction or text direction or text alignment) has been changed.protected void
onSizeChanged
(int width, int height, int prevWidth, int prevHeight) Called when width or height changedvoid
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
setBaseline
(int baseline) Set the offset of the widget's text baseline from the widget's top boundary.void
setBaselineAlignBottom
(boolean aligned) Sets whether the baseline of this view to the bottom of the view.void
setColorFilter
(ColorFilter colorFilter) Apply an arbitrary color filter to the image.void
setCropToPadding
(boolean cropToPadding) Sets whether this ImageView will crop to padding.void
Sets a Image as the content of this ImageView.void
setImageAlpha
(int alpha) Sets the alpha value that should be applied to the image.void
setImageDrawable
(Drawable drawable) Sets a drawable as the content of this ImageView.void
setImageLevel
(int level) Sets the image level, when it is constructed from aLevelListDrawable
.void
setImageMatrix
(Matrix matrix) Adds a transformationMatrix
that is applied to the view's drawable when it is drawn.void
setImageState
(int[] state, boolean merge) Set the state of the currentStateListDrawable
.void
setImageTintBlendMode
(BlendMode blendMode) Specifies the blending mode used to apply the tint specified bysetImageTintList(ColorStateList)
} to the image drawable.void
Applies a tint to the image drawable.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
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 icyllis.modernui.view.View
addFocusables, addFocusables, addKeyboardNavigationClusters, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, awakenScrollBars, awakenScrollBars, callOnClick, cancelLongPress, cancelPendingInputEvents, canReceivePointerEvents, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, clearFocus, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchTouchEvent, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, dp, draw, findFocus, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewByPredicateTraversal, findViewTraversal, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAlpha, getAnimationMatrix, getBackground, getBottom, getBoundsOnScreen, getBoundsOnScreen, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingRect, getElevation, getFadingEdge, getFadingEdgeLength, getFocusable, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalScrollbarHeight, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getInverseMatrix, getKeyDispatcherState, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOnLongClickListener, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getRevealOnFocusHint, getRight, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTextAlignment, getTextDirection, getTooltipText, getTooltipView, getTop, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewRoot, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowVisibility, getX, getY, getZ, handleScrollBarDragging, hasExplicitFocusable, hasFocus, hasFocusable, hasIdentityMatrix, hasNestedScrollingParent, hasOnClickListeners, hasOnLongClickListeners, hasTransientState, hasTranslationTransientState, hasWindowFocus, internalSetPadding, invalidate, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isForegroundInsidePadding, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInLayout, isInScrollingContainer, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isPaddingRelative, isPivotSet, isPressed, isRootNamespace, isScrollbarFadingEnabled, isSelected, isShowingLayoutBounds, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, keyboardNavigationClusterSearch, layout, mapRectFromViewToScreenCoords, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAttachedToWindow, onCancelPendingInputEvents, onCreateContextMenu, onDetachedFromWindow, onDragEvent, onDrawForeground, onDrawScrollBars, onFinishTemporaryDetach, onFocusChanged, onGenericMotionEvent, onHoverChanged, onHoverEvent, onKeyDown, onKeyShortcut, onKeyUp, onLayout, onOverScrolled, onResolveDrawables, onResolvePointerIcon, onScrollChanged, onStartTemporaryDetach, onTouchEvent, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, overScrollBy, performButtonActionOnTouchDown, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFocus, requestFocus, requestFocus, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, requireViewById, resetPivot, resetResolvedDrawables, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveSize, resolveSizeAndState, resolveTextAlignment, resolveTextDirection, restoreDefaultFocus, scheduleDrawable, scrollBy, scrollTo, setActivated, setAlpha, setAnimationMatrix, setBackground, setBottom, setClickable, setContextClickable, setDuplicateParentStateEnabled, setElevation, setEnabled, setFocusable, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setFocusedInCluster, setForeground, setForegroundGravity, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHasTranslationTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setIsRootNamespace, setKeyboardNavigationCluster, setLayoutDirection, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnTouchListener, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSoundEffectsEnabled, setStateListAnimator, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setVisibility, setWillNotDraw, setX, setY, setZ, showContextMenu, showContextMenu, sp, startActionMode, startActionMode, startDragAndDrop, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, willNotDraw
-
Constructor Details
-
ImageView
-
-
Method Details
-
verifyDrawable
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 classView
- 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 then the Drawable is being displayed in the view; else false and it is not allowed to animate.
- See Also:
-
jumpDrawablesToCurrentState
public void jumpDrawablesToCurrentState()Description copied from class:View
CallDrawable.jumpToCurrentState()
on all Drawable objects associated with this view.Also calls
StateListAnimator.jumpToCurrentState()
if there is a StateListAnimator attached to this view.- Overrides:
jumpDrawablesToCurrentState
in classView
-
invalidateDrawable
Description copied from class:View
Invalidates the specified Drawable.- Specified by:
invalidateDrawable
in interfaceDrawable.Callback
- Overrides:
invalidateDrawable
in classView
- Parameters:
dr
- the drawable to invalidate
-
hasOverlappingRendering
public boolean hasOverlappingRendering()Description copied from class:View
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.
Note: The return value of this method is ignored if
View.forceHasOverlappingRendering(boolean)
has been called on this view.- Overrides:
hasOverlappingRendering
in classView
- Returns:
- true if the content in this view might overlap, false otherwise.
-
getAdjustViewBounds
public boolean getAdjustViewBounds()True when ImageView is adjusting its bounds to preserve the aspect ratio of its drawable- Returns:
- whether to adjust the bounds of this view to preserve the original aspect ratio of the drawable
- See Also:
-
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 preserve the original aspect ratio of the drawable.- See Also:
-
getMaxWidth
public int getMaxWidth()The maximum width of this view.- Returns:
- The maximum width of this view
- See Also:
-
setMaxWidth
public void setMaxWidth(int maxWidth) An optional argument to supply a maximum width for this view. Only valid ifsetAdjustViewBounds(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(ScaleType)
to determine how to fit the image within the bounds.- Parameters:
maxWidth
- maximum width for this view- See Also:
-
getMaxHeight
public int getMaxHeight()The maximum height of this view.- Returns:
- The maximum height of this view
- See Also:
-
setMaxHeight
public void setMaxHeight(int maxHeight) An optional argument to supply a maximum height for this view. Only valid ifsetAdjustViewBounds(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(ScaleType)
to determine how to fit the image within the bounds.- Parameters:
maxHeight
- maximum height for this view- See Also:
-
getDrawable
Gets the current Drawable, or null if no Drawable has been assigned.- Returns:
- the view's drawable, or null if no drawable has been assigned.
-
setImageDrawable
Sets a drawable as the content of this ImageView.- Parameters:
drawable
- the Drawable to set, ornull
to clear the content
-
setImageTintList
Applies a tint to the image drawable. Does not modify the current tint mode, which isBlendMode.SRC_IN
by default.Subsequent calls to
setImageDrawable(Drawable)
will automatically mutate the drawable and apply the specified tint and tint mode usingDrawable.setTintList(ColorStateList)
.- Parameters:
tint
- the tint to apply, may benull
to clear tint- See Also:
-
getImageTintList
Get the currentColorStateList
used to tint the image Drawable, or null if no tint is applied.- Returns:
- the tint applied to the image drawable
- See Also:
-
setImageTintBlendMode
Specifies the blending mode used to apply the tint specified bysetImageTintList(ColorStateList)
} to the image drawable. The default mode isBlendMode.SRC_IN
.- Parameters:
blendMode
- the blending mode used to apply the tint, may benull
to clear tint- See Also:
-
getImageTintBlendMode
Gets the blending mode used to apply the tint to the image Drawable- Returns:
- the blending mode used to apply the tint to the image Drawable
- See Also:
-
setImage
Sets a Image as the content of this ImageView.- Parameters:
image
- the image to set
-
setImageState
public void setImageState(int[] state, boolean merge) Set the state of the currentStateListDrawable
. For more information about State List Drawables, see: the Drawable Resource Guide.- Parameters:
state
- the state to set for the StateListDrawablemerge
- if true, merges the state values for the state you specify into the current state
-
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 classView
- Parameters:
selected
- true if the view must be selected, false otherwise
-
setImageLevel
public void setImageLevel(int level) Sets the image level, when it is constructed from aLevelListDrawable
.- Parameters:
level
- The new level for the image.
-
setScaleType
Controls how the image should be resized or moved to match the size of this ImageView.- Parameters:
scaleType
- The desired scaling mode.
-
getScaleType
Returns the current ScaleType that is used to scale the bounds of an image to the bounds of the ImageView.- Returns:
- The ScaleType used to scale the image.
- See Also:
-
getImageMatrix
Returns 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(). -
setImageMatrix
Adds a transformationMatrix
that is applied to the view's drawable when it is drawn. Allows custom scaling, translation, and perspective distortion.- Parameters:
matrix
- The transformation parameters in matrix form.
-
getCropToPadding
public boolean getCropToPadding()Return whether this ImageView crops to padding.- Returns:
- whether this ImageView crops to padding
- See Also:
-
setCropToPadding
public void setCropToPadding(boolean cropToPadding) Sets whether this ImageView will crop to padding.- Parameters:
cropToPadding
- whether this ImageView will crop to padding- See Also:
-
onCreateDrawableState
Description copied from class:View
Generate the newDrawable
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 useView.getDrawableState()
.- Overrides:
onCreateDrawableState
in classView
- 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:
- an array holding the current
Drawable
state of the view. - See Also:
-
onRtlPropertiesChanged
public void onRtlPropertiesChanged(int layoutDirection) Description copied from class:View
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.
- Overrides:
onRtlPropertiesChanged
in classView
- Parameters:
layoutDirection
- the direction of the layout- See Also:
-
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 byView.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
View.setMeasuredDimension(int, int)
to store the measured width and height of this view. Failure to do so will trigger anIllegalStateException
, thrown byView.measure(int, int)
. Calling super.onMeasure() 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 the base one to provide better measurements of their content.
- Overrides:
onMeasure
in classView
- Parameters:
widthMeasureSpec
- width measure specification imposed by the parentMeasureSpec
heightMeasureSpec
- height measure specification imposed by the parentMeasureSpec
-
onSizeChanged
protected void onSizeChanged(int width, int height, int prevWidth, int prevHeight) Description copied from class:View
Called when width or height changed- Overrides:
onSizeChanged
in classView
- Parameters:
width
- new widthheight
- new heightprevWidth
- previous widthprevHeight
- previous height
-
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.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.
- Overrides:
drawableStateChanged
in classView
- See Also:
-
drawableHotspotChanged
public void drawableHotspotChanged(float x, float y) Description copied from class:View
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
View.dispatchDrawableHotspotChanged(float, float)
.Be sure to call through to the superclass when overriding this function.
- Overrides:
drawableHotspotChanged
in classView
- Parameters:
x
- hotspot x coordinatey
- hotspot y coordinate
-
animateTransform
Applies a temporary transformationMatrix
to the view's drawable when it is drawn. Allows custom scaling, translation, and perspective distortion during an animation.This method is a lightweight analogue of
setImageMatrix(Matrix)
to use only during animations as this matrix will be cleared after the next drawable update or view's bounds change.- Parameters:
matrix
- The transformation parameters in matrix form.
-
onDraw
Description copied from class:View
Draw the content of this view, implement this to do your drawing.Note that (0, 0) will be the top left of the bounds, and (width, height) will be the bottom right of the bounds.
-
getBaseline
public int getBaseline()Return the offset of the widget's text baseline from the widget's top boundary.
- Overrides:
getBaseline
in classView
- Returns:
- the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported.
-
setBaseline
public 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.- Parameters:
baseline
- The baseline to use, or -1 if none is to be provided.- See Also:
-
setBaselineAlignBottom
public void setBaselineAlignBottom(boolean aligned) Sets whether the baseline of this view to the bottom of the view. Setting this value overrides any calls to setBaseline.- Parameters:
aligned
- If true, the image view will be baseline aligned by its bottom edge.
-
getBaselineAlignBottom
public boolean getBaselineAlignBottom()Checks whether this view's baseline is considered the bottom of the view.- Returns:
- True if the ImageView's baseline is considered the bottom of the view, false if otherwise.
- See Also:
-
getColorFilter
Returns the active color filter for this ImageView.- Returns:
- the active color filter for this ImageView
- See Also:
-
setColorFilter
Apply an arbitrary color filter to the image.- Parameters:
colorFilter
- the color filter to apply (can be null)- See Also:
-
getImageAlpha
public int getImageAlpha()Returns the alpha that will be applied to the drawable of this ImageView.- Returns:
- the alpha value that will be applied to the drawable of this ImageView (between 0 and 255 inclusive, with 0 being transparent and 255 being opaque)
- See Also:
-
setImageAlpha
public void setImageAlpha(int alpha) Sets the alpha value that should be applied to the image.- Parameters:
alpha
- the alpha value that should be applied to the image (between 0 and 255 inclusive, with 0 being transparent and 255 being opaque)- See Also:
-
onVisibilityAggregated
public void onVisibilityAggregated(boolean isVisible) Description copied from class:View
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.- Overrides:
onVisibilityAggregated
in classView
- Parameters:
isVisible
- true if this view and all of its ancestors areView.VISIBLE
and this view's window is also visible
-