Added in API level 1

ImageView


open class ImageView : View
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.ImageView

Displays image resources, for example android.graphics.Bitmap or android.graphics.drawable.Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.

The following XML snippet is a common example of using an ImageView to display an image resource:

<LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      <ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/my_image"
          android:contentDescription="@string/my_image_description"
          />
  </LinearLayout>
  

To learn more about Drawables, see: Drawable Resources. To learn more about working with Bitmaps, see: Handling Bitmaps.

Summary

Nested classes

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: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 The tinting color for the image.
Inherited XML attributes
Inherited constants
Public constructors
ImageView(context: Context!)

ImageView(context: Context!, attrs: AttributeSet?)

ImageView(context: Context!, attrs: AttributeSet?, defStyleAttr: Int)

ImageView(context: Context!, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

Applies a temporary transformation Matrix to the view's drawable when it is drawn.

Unit

Removes the image's android.graphics.ColorFilter.

open Unit

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

open CharSequence!

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

open Boolean

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

open Int

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

open Boolean

Checks whether this view's baseline is considered the bottom of the view.

open ColorFilter!

Returns the active color filter for this ImageView.

open Boolean

Return whether this ImageView crops to padding.

open Drawable!

Gets the current Drawable, or null if no Drawable has been assigned.

open Int

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

open Matrix!

Returns the view's optional matrix.

open BlendMode?

Gets the blending mode used to apply the tint to the image Drawable

open ColorStateList?

Get the current android.content.res.ColorStateList used to tint the image Drawable, or null if no tint is applied.

open PorterDuff.Mode?

Gets the blending mode used to apply the tint to the image Drawable

open Int

The maximum height of this view.

open Int

The maximum width of this view.

open ImageView.ScaleType!

Returns the current ScaleType that is used to scale the bounds of an image to the bounds of the ImageView.

open Boolean

Returns whether this View has content which overlaps.

open Unit

Invalidates the specified Drawable.

open Boolean

Indicates whether this View is opaque.

open Unit

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

open IntArray!

Generate the new android.graphics.drawable.Drawable state for this view.

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

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

open Unit

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.

open Unit
setAdjustViewBounds(adjustViewBounds: Boolean)

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

open Unit
setAlpha(alpha: Int)

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

open Unit
setBaseline(baseline: Int)

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

open Unit

Sets whether the baseline of this view to the bottom of the view.

open Unit

Apply an arbitrary colorfilter to the image.

Unit

Set a tinting option for the image.

Unit

Sets a tinting option for the image.

open Unit
setCropToPadding(cropToPadding: Boolean)

Sets whether this ImageView will crop to padding.

open Unit

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

open Unit

Sets a Bitmap as the content of this ImageView.

open Unit

Sets a drawable as the content of this ImageView.

open Unit

Sets the content of this ImageView to the specified Icon.

open Unit

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

open Unit

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

open Unit

Sets a drawable as the content of this ImageView.

open Unit
setImageState(state: IntArray!, merge: Boolean)

Set the state of the current android.graphics.drawable.StateListDrawable.

open Unit

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

open Unit

Applies a tint to the image drawable.

open Unit

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

open Unit

Sets the content of this ImageView to the specified Uri.

open Unit
setMaxHeight(maxHeight: Int)

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

open Unit
setMaxWidth(maxWidth: Int)

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

open Unit

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

open Unit
setSelected(selected: Boolean)

Changes the selection state of this view.

open Unit
setVisibility(visibility: Int)

Set the visibility state of this view.

Protected methods
open Unit

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

open Unit

This is called when the view is attached to a window.

open Unit

This is called when the view is detached from a window.

open Unit
onDraw(canvas: Canvas)

Implement this to do your drawing.

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

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

open Boolean
setFrame(l: Int, t: Int, r: Int, b: Int)

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

Inherited functions