0

I need to put buttons in different places on an image, its a floorplan and I want to use the image for navigation to each of the rooms.

I have an idea that I need two images the top one holds the floorplan and the bottom one holds the buttons - which are really different coloured areas. I want to show the user the top image but get touches from the bottom picture. If I can get the colour of the button/area the user has clicked then I can tell what room they want to go to and I'll be able to have my buttons any shape I like.

I found the idea but I can't find any tutorials or instruction to help me. I'm currently looking at GL ES 1.0 but I'm not sure if its the right way to do it.

Any help would be very much appreciatted

thanks

kameny
  • 2,372
  • 4
  • 30
  • 40
Martin
  • 133
  • 1
  • 11

2 Answers2

3

You can set an OnTouchListener to your Image:

image.setOnTouchListener(new View.OnTouchListener() {

 @Override
 public boolean onTouch(View v, MotionEvent event) {
 event.getX();
 event.getY();
 return false;
      }
});

With getX and getY you will get the coordinates of the picture which has been pressed. Now you just need a list of the areas which respond to the "clicks".
I suggest you do that with a list of Rect-Objects. Every Rect-Object represents a clickable rectangle inside your picture. A Rect object provides the method contains(x, y) to test if the coordinates delivered from the onTouchListener are inside it.

sealz
  • 5,348
  • 5
  • 40
  • 70
Thommy
  • 5,070
  • 2
  • 28
  • 51
1

Sorry I answered before I fully read the question. My solution is a simpler way but will not allow you to form and shape them as well as your idea. Let me play around and maybe I can update this answer. Good Luck

If I understand you correctly you can place the buttons over the image and then set them to invisible. This way they can't be seen but can still be pressed.

View b = findViewById(R.id.button); 
b.setVisibility(View.GONE);
//I can't remember off the top of my head but it might be
b.setVisibility(View.INVISIBLE)

And incase my code is off here is a backup Link

Community
  • 1
  • 1
sealz
  • 5,348
  • 5
  • 40
  • 70
  • thanks harper89, I thought if I could get the colour of the area then I could make my areas any shape I liked and also it would help if I allowed my image to became distorted, if both images are the same size then any distortion would be mirrored in the pressable areas. I am a bit of a newbie at this I just assumed the image would need to go under and stay visible but now I don't see why an image can be invisible and not have colours (thanks also to @Thommy) – Martin Feb 02 '12 at 16:00
  • @Martin The click action by color clicked seems like a much cooler and robust idea. Hopefully in the end you get what you need. Enjoy – sealz Feb 02 '12 at 16:04