android中的ontouch:獲取X和Y坐標並在該點上繪製圓 (ontouch in android: getting X and Y coordinates and drawing circle on that point)


問題描述

android中的ontouch:獲取X和Y坐標並在該點上繪製圓 (ontouch in android: getting X and Y coordinates and drawing circle on that point)

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

(by yuva ツShreeshaDas)

參考文件

  1. ontouch in android: getting X and Y coordinates and drawing circle on that point (CC BY‑SA 3.0/4.0)

#draw #android-canvas #Android #ontouchlistener






相關問題

使用Java繪製維恩圖 (Draw Venn diagram using Java)

android中的ontouch:獲取X和Y坐標並在該點上繪製圓 (ontouch in android: getting X and Y coordinates and drawing circle on that point)

如何在android上將谷歌地圖圖層作為片段佈局移動 (how to move google map layers as fragment layout on android)

onTouch() 無法繪製畫布 (onTouch() can't draw canvas)

佈局僅在屏幕關閉或離開應用程序並返回後顯示兒童 (Layout only shows children after screen turn off or leaving the app and coming back)

將形狀對象的 ArrayList 繪製到框架 (Paint ArrayList of Shape Objects to Frame)

多線程圖形 (multithreading Graphics)

一次性繪製所有 DrawableGameComponents (Drawing all DrawableGameComponents in a single batch)

html5畫布繪製帶有額外數據的圓形變量 (html5 canvas draw circle variables with extra data)

iphone初學者問題:畫一個矩形。我究竟做錯了什麼? (Beginner iphone question: drawing a rectangle. What am I doing wrong?)

連接 4 Android Studio 繪製空格 (Connect 4 Android Studio Draw empty spaces)

矩形不動 (Rectangle is not moving)







留言討論