I am trying to make part of my image clickable. In this case I have 24 port switch and I want when user click on a port to display the port number. I already have do the zooming and tried to insert rectangles over the image, but I am still new in the Android Development so I am not so sure how to accomplish the task.
Here is my code to create rectangles and put on the picture: (the idea is that I have one class Rectangles that keeps the port number and some text so I can retrieve them)
public class MainActivity extends Activity{
ImageView DrawingImage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DrawingImage = (ImageView) this.findViewById(R.id.image);
Bitmap bitmap2 = Bitmap.createBitmap((int) getWindowManager()
.getDefaultDisplay().getWidth(), (int) getWindowManager()
.getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap2);
DrawingImage.setImageBitmap(bitmap2);
// Draw Rectangle
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.FILL);
float left = 20;
float top = 20;
float right = 50;
float bottom = 100;
canvas.drawRect(left, top, right, bottom, paint);
Zoom image = (Zoom) findViewById(R.id.image);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test);
image.setImageBitmap(bitmap);
int posX=(int)image.getX();
int posY=(int)image.getY();
double height=image.getHeight();
double width=image.getWidth();
}
}
But when I run the App I cannot see the Rectangle. Even if i declare the picture before the rectangle I can see only the rectangle.
Any suggestions?
Any help will be appreciated.
Thank you in advance!
Best regards, Dimtiar Georgiev