The moose likes Android and the fly likes replace grid image with image button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "replace grid image with image button" Watch "replace grid image with image button" New topic

replace grid image with image button

Sara Brown
Ranch Hand

Joined: Feb 22, 2012
Posts: 55
im curios.

my project need user to mark any part of the picture that related to user's spec.
then it will send to server and the server can see the picture that been mark by the user.

im thinking of, can i use button instead of grid? this button will be put together and it will appears as the real picture.

is this option efficient?
Sara Brown
Ranch Hand

Joined: Feb 22, 2012
Posts: 55
however, when doing grid or image button the picture seems have border between each other? is there any other way?
Sara Brown
Ranch Hand

Joined: Feb 22, 2012
Posts: 55
please, does anybody know how to do?
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
You don't need to use buttons.

I suggest that you do this:

1) Use an ImageView
2) Set android:scaleType="matrix"
3) Implement your own OnTouchListener
4) Override onTouch
5) In onTouch look for these cases:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
float[] coords = getPointerCoords(view, rawEvent); //view is passed to onTouch
imagePt.x = coords[0];
imagePt.y = coords[1];
6) Make getPointerCoords(view, rawEvent) look like this:

final float[] getPointerCoords(ImageView view, MotionEvent e)
final int index = e.getActionIndex();
final float[] coords = new float[] { e.getX(index), e.getY(index) };
Matrix matrix = new Matrix();
matrix.postTranslate(view.getScrollX(), view.getScrollY());
return coords;

That will return the point upon where the image was touched.
Don't get me started about those stupid light bulbs.
subject: replace grid image with image button
Similar Threads
Writing a pixel mapping program
Image on a button in jsf
Convert InputStream to a File in Memory
How to get image on a button using applet
Image resizing