example for you to share the specific code for Android to implement the irregular area click events for your reference, the details are as follows:

first look at the effect of

 @Override protected void onDraw (Canvas canvas) {super.onDraw (canvas); if (list = = = = {}); / / / / / / / / this place to be. Concat method can not be used by this method / / / / canvas.concat (mMatrix); / / / / / / canvas.restore (); canvas.scale (scale, scale); canvas.drawColor (Color.YELLOW); for (int i = 0;); / / drawing edge The color mPaint.setStrokeWidth (2); mPaint.setStyle (Paint.Style.STROKE); mPaint.setColor (Color.GRAY); canvas.drawPath (path.getmPath (), mPaint);} if (mPath! = null) {//mPath represents the selected area, and if it is not empty, the selected area is clicked. Nt.setStrokeWidth (1); mPaint.setStyle (Paint.Style.FILL); mPaint.setColor (Color.GREEN); mPaint.setShadowLayer (8,2,2, Color.BLACK); canvas.drawPath (mPath, mPaint);} mPaint.clearShadowLayer ();} the above method can produce a map, But without clicking the event, the next implementation of the click event code is as follows: 

 @Override public Boolean onTouchEvent (MotionEvent event) {if (event.getAction () = = MotionEvent.ACTION_DOWN) {/ / / Click Null) for (int i = 0; I < list.size (); i++); / / / / more path is traversing CityPath cityPath = list.get. Ath.getmPath (); postInvalidate (); Toast.makeText (getContext (), cityPath.getTitle (), Toast.LENGTH_SHORT).Show (); break;}} return super.onTouchEvent (event);} 

. The main core of the event implementation is whether the broken point is in the region. The implementation code is as follows:

 public Boolean isArea (float x, float y) {RectF r=new RectF (); / / / / / / / / / Return re.contains ((int) x, (int) y);} the code above 

can be clicked in the irregular area, and the next main file is how to ensure that the display adaption on the phone can be different by parsing the SVG file. The method I realized here is to count the smallest outer rectangle of each path. Come out, then integrate to get the minimum value of all path regions, and then compare with the size of the control to calculate the scale of the scaling ratio code as follows: the boundary of the

 / / processing path, mCityPath.getmPath ().ComputeBounds (mRectF, true), mViewAttr.colSize (mRectF); public void. OlSize (RectF mRectF) {left = left = = null? MRectF.left: Math.min (mRectF.left, left); top = top = = = Ottom, bottom);} 

after the completion of the completion of the completion of the code, the following is the address of the code, if there is an improved place to welcome the

Download: code address above is all of the content of this article, hope to help you, and also hope big The home of the script is supported by a lot of home.

This paper fixed link:http://www.script-home.com/android-custom-controls-to-achieve-click-events-in-irregular-regions.html | Script Home | +Copy Link

Article reprint please specify:Android custom controls to achieve click events in irregular regions | Script Home

You may also be interested in these articles!