ontouch in android: getting X and Y coordinates an

2019-07-11 20:38发布

问题:

in my application on ontouch of screen i'm getting the coordinates(x.y), after that on that position i'm drawing a circle.but when i'm drawing a circle on that position.it always draw a circle on upper left side corner of images on some pt.s .i'm not getting why this is happening.please help me.

        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

             if(event.getAction()==MotionEvent.ACTION_UP) {

               Log.d("position", event.getX() + "-" + event.getY());
                   System.out.println("bitmap......"+paths[0]+"draw...."+dd);
                    Paint paint = new Paint();
                    paint.setAntiAlias(true);

                   paint.setColor(getResources().getColor(R.color.Yellow)) ;
                   paint.setAlpha(opacity);

                         // create canvas to draw on the bitmap
                    Canvas canvas = new Canvas(mutbit);
                    canvas.drawCircle(event.getX(),event.getY(), 10, paint);

                    im.setAdjustViewBounds(true);
                    im.setImageBitmap(mutbit);
                    dd[1]=im.getDrawable();
                    Bitmap aa=mutbit.copy(Bitmap.Config.ARGB_4444,false);//mutbit=bb[tabCount].copy(Bitmap.Config.ARGB_4444, true);
                    bb[1]=aa;
                    return true;
                }
             return false;
        }

回答1:

Try this draw circle on Action down event.getAction()==MotionEvent.ACTION_UP to event.getAction() == MotionEvent.ACTION_DOWN