android: finding the position of a click within a button -
i have set of imagebuttons
placed within relative layout, , each imagebutton
has shape within visible while rest of set alpha. have set these buttons overlap, , trying code when alpha part of 1 button pressed, ignores button , checks button underneath it. using ontouch()
ontouchlistener
x
, y
coordinates of touch on screen, calculated based on whole screen can tell. there way use position found event.getx()
, event.gety()
@ button on screen , see if spot clicked on button transparent or not?
use view.getlocationonscreen()
and/or getlocationinwindow()
. https://stackoverflow.com/a/2226048/1979882
in order check if alpha-channel exists, use:
public static bitmap loadbitmapfromview(view v) { bitmap bitmap; v.setdrawingcacheenabled(true); bitmap = bitmap.createbitmap(v.getdrawingcache()); v.setdrawingcacheenabled(false); return bitmap; }
and detect argb value particular pixel.
int pixel = bitmap.getpixel(x,y);
now can each channel with:
int alphavalue = color.alpha(pixel); int redvalue = color.red(pixel); int bluevalue = color.blue(pixel); int greenvalue = color.green(pixel);
Comments
Post a Comment