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

open CharSequence!

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

open Unit

Invalidates the specified Drawable.

open Boolean

open Unit

open IntArray!

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

open Unit

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)

open Unit
setVisibility(visibility: Int)

Protected methods
open Unit

open Unit

open Unit

open Unit
onDraw(canvas: Canvas)

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

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