What is the purpose of Drawable setHotspot on Android 5.0 (API 21)?

Looking at Drawable docs, we have a new setHotspot (float x, float y) method setHotspot (float x, float y) with a description:

Locates the access point within the acceptable range.

With no other explanation on this page, I wonder what the purpose is.

+5
source share
1 answer

Hotspots are used to transmit touch events to RippleDrawable, but can also be used by custom drawings. If you are implementing a custom view that manages its own drawings, you will need to call setHotspot () from the drawableHotspotChanged () method for the series to work with touch orientation.

From 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); } } 

From FrameLayout.java, which manages its own mForeground drawable:

 @Override public void drawableHotspotChanged(float x, float y) { super.drawableHotspotChanged(x, y); if (mForeground != null) { mForeground.setHotspot(x, y); } } 
+9
source

Source: https://habr.com/ru/post/1205077/


All Articles