Android 5.0(API 21)上的Drawable setHotspot的目的是什么?

Ran*_*ku' 7 android android-drawable android-5.0-lollipop

查看Drawable文档,我们有一个新方法setHotspot (float x, float y),其描述如下:

指定热点在drawable中的位置.

在该页面上没有其他解释,我想知道目的是什么.

ala*_*anv 12

热点用于将触摸事件传递到RippleDrawable中,但也可以由自定义drawable使用.如果要实现管理其自己的drawable的自定义View,则需要从drawableHotspotChanged()方法调用setHotspot()以使以触摸为中心的涟漪正常工作.

从View.java:

@Override
public boolean onTouchEvent(MotionEvent event) {
    ...
            case MotionEvent.ACTION_MOVE:
                drawableHotspotChanged(x, y);
    ...
}


/**
 * This function is called whenever the view hotspot changes and needs to
 * be propagated to drawables managed by the view.
 * <p>
 * Be sure to call through to the superclass when overriding this function.
 *
 * @param x hotspot x coordinate
 * @param y hotspot y coordinate
 */
public void drawableHotspotChanged(float x, float y) {
    if (mBackground != null) {
        mBackground.setHotspot(x, y);
    }
}
Run Code Online (Sandbox Code Playgroud)

来自FrameLayout.java,它管理自己的mForeground drawable:

@Override
public void drawableHotspotChanged(float x, float y) {
    super.drawableHotspotChanged(x, y);

    if (mForeground != null) {
        mForeground.setHotspot(x, y);
    }
}
Run Code Online (Sandbox Code Playgroud)