2014-10-20 187 views
5

望着Drawable文檔,我們有一個新的方法setHotspot (float x, float y)用的描述:Android 5.0(API 21)上可繪製setHotspot的用途是什麼?

指定繪製中的熱點位置。

在該頁面上沒有其他解釋,我不知道目的是什麼。

+0

我發現這篇文章(但它是舊):HTTP:// blahti .wordpress.com/2012/06/26/images-with-clickable-areas /也許這個熱點有相同的感覺... – krossovochkin 2014-10-20 08:58:33

+0

通過鼻子,這是設置爲觸摸感的點的座標? – 2014-10-20 09:04:47

回答

9

熱點用於將觸摸事件傳遞到RippleDrawable,但也可以由自定義可繪製使用。如果您正在實現一個自定義視圖來管理自己的可繪製對象,則需要從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繪製:

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

    if (mForeground != null) { 
     mForeground.setHotspot(x, y); 
    } 
}