java.lang.Object | |||
android.view.View | Drawable.Callback KeyEvent.Callback | ||
android.widget.ImageView |
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.
ImageView.ScaleType | Options for scaling the bounds of an image to the bounds of this view. |
Attribute name | Related methods | |
---|---|---|
android:adjustViewBounds | setAdjustViewBounds(boolean) |
Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable. |
android:maxHeight | setMaxHeight(int) |
An optional argument to supply a maximum height for this view. |
android:maxWidth | setMaxWidth(int) |
An optional argument to supply a maximum width for this view. |
android:scaleType | setScaleType(ImageView.ScaleType) |
Controls how the image should be resized or moved to match the size of this ImageView. |
android:src | setImageResource(int) |
Sets a drawable as the content of this ImageView. |
android:tint | setColorFilter(int,PorterDuff.Mode) |
Set a tinting color for the image
Must be a color value, in the form of " |
ImageView(Context context) | ||||||
ImageView(Context context, AttributeSet attrs) | ||||||
ImageView(Context context, AttributeSet attrs, int defStyle) |
final | void | clearColorFilter() | ||||
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. | ||||||
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. | ||||||
final | void | setColorFilter(int color, PorterDuff.Mode mode) | ||||
Set a tinting option for 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 | 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. | ||||||
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. |
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 | onSetAlpha(int alpha) | |||||
Invoked if there is a Transform that involves alpha. | ||||||
boolean | setFrame(int l, int t, int r, int b) | |||||
Assign a size and position to this view. |
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.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), db (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.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), db (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.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
matrix | 0 | |
fitXY | 1 | |
fitStart | 2 | |
fitCenter | 3 | |
fitEnd | 4 | |
center | 5 | |
centerCrop | 6 | |
centerInside | 7 |
This corresponds to the global attribute resource symbol scaleType.
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.
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.
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.
dr | the drawable to invalidate |
---|
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. |
---|
adjustViewBounds | Whether to adjust the bounds of this view to presrve the original aspect ratio of the drawable |
---|
cf | the colorfilter to apply (may be null) |
---|
color | Color tint to apply. |
---|---|
mode | How to apply the color. The standard mode is SRC_ATOP |
bm | The bitmap to set |
---|
drawable | The drawable to set |
---|
resId | the resource identifier of the the drawable |
---|
uri | The Uri of an image |
---|
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(ImageView.ScaleType) to determine how to fit the image within the bounds.
maxHeight | maximum height for this view |
---|
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(ImageView.ScaleType) to determine how to fit the image within the bounds.
maxWidth | maximum width for this view |
---|
scaleType | The desired scaling mode. |
---|
selected | true if the view must be selected, false otherwise |
---|
Be sure to call through to the super class when overriding this function.
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. |
---|
Be sure to call through to the superclass when overriding this function.
canvas | the canvas on which the background will be drawn |
---|
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 overriden 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()).
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. |
alpha | The alpha (0..255) to apply to the view's drawing |
---|
l | Left position, relative to parent |
---|---|
t | Top position, relative to parent |
r | Right position, relative to parent |
b | Bottom position, relative to parent |
Copyright 2007 Google Inc. | Build 0.9_r1-98467 - 14 Aug 2008 18:48 |