java - How to determined if the user touch my bitmap? -


how determine if user clicked in regions of imageview?

i'm having little bit of difficulty setting (x,y) coordinate bounds detect when particular bitmap being clicked on or not.

for example if bitmap's position (75,75),say. i.e. top left corner @ point, if user touches screen @ point (x,y), simple conditional:

i have 4 image position draw in canvas it's (75,75),(645,75),(1215,75) , (75,490).

it wasn't able determined click give me message, "mimaget" instead of others.

@override public boolean ontouch(view v, motionevent event) {     int x = (int) event.getx();     int y = (int) event.gety();     switch (event.getaction()) {         case motionevent.action_down:               if (x >= 75 && x < (75 + mimaget.getwidth())                     && y >= 75 && y < (75 + mimaget.getheight())) {                 toast.maketext(getactivity(), "mimaget", toast.length_short).show();                 log.e("touched", "x: " + x + " y: " + y + mimaget.getwidth() + "-" + mimaget.getheight());             }              if (x >= 645 && x < (645 + mimageth.getwidth())                     && y >= 75 && y < (75 + mimageth.getheight())) {                 toast.maketext(getactivity(), "mimageth", toast.length_short).show();                 log.e("touched", "x: " + x + " y: " + y + mimageth.getwidth() + "-" + mimageth.getheight());             }              if (x >= 1215 && x < (1215 + mimagef.getwidth())                     && y >= 75 && y < (75 + mimagef.getheight())) {                 toast.maketext(getactivity(), "mimagef", toast.length_short).show();                 log.e("touched", "x: " + x + " y: " + y + mimagef.getwidth() + "-" + mimagef.getheight());             }              if (x >= 75 && x < (75 + mimageo.getwidth())                     && y >= 490 && y < (490 + mimageo.getheight())) {                 toast.maketext(getactivity(), "mimageo", toast.length_short).show();                 log.e("touched", "x: " + x + " y: " + y + mimageo.getwidth() + "-" + mimageo.getheight());             }              return true;     }     return false; } 

thankyou :)

@override public boolean ontouch(view v, motionevent event) {     int x = (int) event.getx();     int y = (int) event.gety();     switch (event.getaction()) {         case motionevent.action_down:              if (x >= 75 && x < (75 + mback.getwidth())                     && y >= 75 && y < (75 + mback.getheight())) {                 toast.maketext(getactivity(), "zone1: " + x +"-" + y, toast.length_short).show();             }              if (x >= 645 && x < (645 + mback.getwidth())                     && y >= 75 && y < (75 + mback.getheight())) {                 toast.maketext(getactivity(), "zone2: " + x +"-" + y, toast.length_short).show();             }              if (x >= 1215 && x < (1215 + mback.getwidth())                     && y >= 75 && y < (75 + mback.getheight())) {                 toast.maketext(getactivity(), "zone3: " + x +"-" + y, toast.length_short).show();             }              if (x >= 75 && x < (75 + mback.getwidth())                     && y >= 490 && y < (490 + mback.getheight())) {                 toast.maketext(getactivity(), "zone4: " + x +"-" + y, toast.length_short).show();             }              log.d("touched", "x: " + x + " y: " + y + mimaget.getwidth() + "-" + mimaget.getheight());               return true;     }     return false; } 

could please try 1 part of code instead example.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -