答案 0 :(得分:11)
热点用于将触摸事件传递到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);
}
}
来自FrameLayout.java,它管理自己的mForeground drawable:
@Override
public void drawableHotspotChanged(float x, float y) {
super.drawableHotspotChanged(x, y);
if (mForeground != null) {
mForeground.setHotspot(x, y);
}
}