Satz Napster
Satz Napster

Reputation: 11

How to get the x y position of a view after zoom-in in android

I am Beginner for android, am looking for xy position of a view in zoom-in page but i tried a lot i cant able to get that.I used this below coding, but im getting the same position before and after the zoom. Please any one post the code for finding the xy position after zoom it.

 private int fieldImgXY[] = new int[2];
 v.getLocationOnScreen(fieldImgXY);
 Log.v("Log",fieldImgXY[0]+" "+fieldImgXY[1]);

My full code:

     zoom = (ZoomView) findViewById(R.id.maincontainerScroller);    

     imageView = new ImageView(this);
     imageView.setImageResource(R.drawable.ic_launcher);
     imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
     zoom.addView(imageView);    

     imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            v.getLocationOnScreen(fieldImgXY);
            Log.v("Log",fieldImgXY[0]+" "+fieldImgXY[1]);

        }
    });

Upvotes: 0

Views: 1395

Answers (1)

Andres Cárdenas
Andres Cárdenas

Reputation: 738

for take the absolute coordinates from image I use this method:

void calculeAbsoluteCoorde(MotionEvent e){
    float []m = new float[9];
    matrix.getValues(m);
    float transX = m[Matrix.MTRANS_X] * -1;
    float transY = m[Matrix.MTRANS_Y] * -1;
    float scaleX = m[Matrix.MSCALE_X];
    float scaleY = m[Matrix.MSCALE_Y];
    lastTouchX = (int) ((e.getX() + transX) / scaleX);
    lastTouchY = (int) ((e.getY() + transY) / scaleY);
    lastTouchX = Math.abs(lastTouchX);
    lastTouchY = Math.abs(lastTouchY);
}

I supose u used matrix for zoom, i wish it help u

Upvotes: 1

Related Questions