I have scaled the image to fit the imageview, so now I want to get the rect of imageview so that I can make 1 count for every finger drag made only inside the imageview and not outside. What I have done can be seen below but it is not working because it isn't showing any detection when I drag my finger up and down in the imageview, if it did it should increment 1 for every drag but nothing happens. What am I doing wrong?
Inside onCreate of the main activity:
redShape = (ImageView) findViewById(R.id.image1);
scaleImage(redShape, 300);
Inside Motion Event, Action down:
rect = new Rect(redShape.getLeft(),redShape.getTop(),redShape.getRight(),redShape.getBottom());
Inside Motion Event, Action move:
if ((posY > redShape.getTop() || posY <redShape.getBottom()) && rect.contains(redShape.getLeft() + posX, redShape.getTop() + posY)){
Inside the above if statement I have some code that increments 1 for every drag made in a vertical motion (up and down).
EDIT:
This is what I've done but for some reason like before it still detects a drag in the area above the image.
In the onCreate of main activity:
redShape = (ImageView) findViewById(R.id.image1);
drawable2 = getResources().getDrawable(R.drawable.red_shape);
int h = drawable2.getIntrinsicHeight();
int w = drawable2.getIntrinsicWidth();
Matrix m = redShape.getImageMatrix();
RectF drawableRect = new RectF(0, 0, w, h);
RectF viewRect = new RectF(0, 0, redShape.getWidth(), redShape.getHeight());
m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.FILL);
redShape.setImageMatrix(m);
EDIT 2:
m = redShape.getImageMatrix();
Have the following code in either action down (oldX,oldY touch points) or move (posX,posY touch points):
float[] touchPoint = new float[] {oldX, oldY};
m.mapPoints(touchPoint);