Most visited

Recently visited

AppCompatImageView

public class AppCompatImageView
extends ImageView implements TintableBackgroundView

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ android.support.v7.widget.AppCompatImageView


支持旧版平台兼容功能的 ImageView ,包括:

当您在布局中使用ImageView时,这将自动使用。 编写自定义视图时,您只需手动使用此类。

Summary

Inherited XML attributes

From class android.widget.ImageView
From class android.view.View

Inherited constants

From class android.view.View

Inherited fields

From class android.view.View

Public constructors

AppCompatImageView(Context context)
AppCompatImageView(Context context, AttributeSet attrs)
AppCompatImageView(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

boolean hasOverlappingRendering()

返回此视图是否包含重叠的内容。

void setBackgroundDrawable(Drawable background)

此方法已弃用。 改为使用setBackground(Drawable)

void setBackgroundResource(int resId)

将背景设置为给定的资源。

void setImageResource(int resId)

设置一个drawable作为这个ImageView的内容。

Protected methods

void drawableStateChanged()

只要视图的状态发生变化,就会调用此函数,使得它影响所显示的可绘制状态。

Inherited methods

From class android.widget.ImageView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.support.v4.view.TintableBackgroundView

Public constructors

AppCompatImageView

AppCompatImageView (Context context)

Parameters
context Context

AppCompatImageView

AppCompatImageView (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

AppCompatImageView

AppCompatImageView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

Public methods

hasOverlappingRendering

boolean hasOverlappingRendering ()

返回此视图是否包含重叠的内容。

打算被特定视图类型覆盖的此函数是在视图上设置alpha时的优化。 如果渲染在alpha <1的视图中重叠,则该视图将被拖到屏幕外的缓冲区,然后合成到位,这可能很昂贵。 如果视图没有重叠的渲染,视图可以直接用适当的alpha值绘制每个基元。 重叠渲染的一个例子是带有背景图像的TextView,例如Button。 非重叠渲染的一个例子是没有背景的TextView或只有前景图像的ImageView。 默认实现返回true; 如果子类有可以优化的情况,子类应该重写。

当前实现在saveLayer和saveLayerAlpha方法 Canvas必要,一个视图,如果它使用的方法在内部,而没有经过返回true CLIP_TO_LAYER_SAVE_FLAG

注意:如果在此视图上调用 forceHasOverlappingRendering(boolean) ,则此方法的返回值将被忽略。

Returns
boolean true if the content in this view might overlap, false otherwise.

setBackgroundDrawable

void setBackgroundDrawable (Drawable background)

此方法已弃用。
改为使用setBackground(Drawable)

Parameters
background Drawable

setBackgroundResource

void setBackgroundResource (int resId)

将背景设置为给定的资源。 该资源应该引用可绘制对象或0来移除背景。

Parameters
resId int: The identifier of the resource.

setImageResource

void setImageResource (int resId)

设置一个drawable作为这个ImageView的内容。

这会在UI线程上进行位图读取和解码,这会导致延迟打嗝。 如果这是一个问题,请考虑使用setImageDrawable(android.graphics.drawable.Drawable)setImageBitmap(android.graphics.Bitmap)BitmapFactory

Parameters
resId int: the resource identifier of the drawable

Protected methods

drawableStateChanged

void drawableStateChanged ()

只要视图的状态发生变化,就会调用此函数,使得它影响所显示的可绘制状态。

如果View有一个StateListAnimator,它也将被调用来运行必要的状态改变动画。

重写此功能时,一定要调用超类。

Hooray!