Hi there,
I am drawing a chart (image attached) using canvas. On the chart I wanted to find out which rectangle is clicked and based on that take some action. I am using following logic -
- If it is a singleclick then take X & Y coordinate
- Run through each rectangle's X1,Y1 and X2,Y2 and find out under which rectangle these X, Y coordinates lies.
- The issue is that I am using dip unit to draw rectangle and storing its X1,Y1 and X2,Y2 values in dip unit. However the X, Y coordinates gives me values in pixels and there is vast difference between pixels and dips unit so no match is found.
My question
is how can I convert Dip to pixels or vice versa? What is the conversion factor?
Is there any other way to find out which rectangle is clicked by user? I am using canvas.drawrect method to draw rectangles.
I am drawing a chart (image attached) using canvas. On the chart I wanted to find out which rectangle is clicked and based on that take some action. I am using following logic -
- If it is a singleclick then take X & Y coordinate
- Run through each rectangle's X1,Y1 and X2,Y2 and find out under which rectangle these X, Y coordinates lies.
- The issue is that I am using dip unit to draw rectangle and storing its X1,Y1 and X2,Y2 values in dip unit. However the X, Y coordinates gives me values in pixels and there is vast difference between pixels and dips unit so no match is found.
My question
is how can I convert Dip to pixels or vice versa? What is the conversion factor?
Is there any other way to find out which rectangle is clicked by user? I am using canvas.drawrect method to draw rectangles.