continous zoom on image: get matrix from animation?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

continous zoom on image: get matrix from animation?

Postby emotioner » Mon Jun 29, 2009 10:08 pm

Hi,

I am simulating iPone zoom on a image: single tab to zoom in at the point of contact. I am using an ImageView and Animation to do this. The problem is I don't know how to get the Matrix object after the animation has started. I guess I need this to get the _real_ transformation center for the next zoom. MotionEvent.getX() and getY() only give me the touch point coordinates on the widget when the widget doen;t have and transformation applied. So my code only works for the first time tab. Any subsequent tabs appear jumpy since the real scale center has been transformed.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // code snippet starts here.
  2.  
  3. Interpolator i = new DecelerateInterpolator(2.0f);
  4.  
  5.         ScaleAnimation scaleAnim = new ScaleAnimation(currentXScale, currentXScale + scaleStep, currentXScale, currentYScale + scaleStep, cX, cY);
  6.  
  7.         scaleAnim.setAnimationListener(new AnimationListener(){
  8.  
  9.                 public void onAnimationEnd(Animation anim) {
  10.  
  11.                         currentXScale += scaleStep;
  12.  
  13.                         currentYScale += scaleStep;
  14.  
  15.                 }
  16.  
  17.                 public void onAnimationStart(Animation anim) {
  18.  
  19.                        
  20.  
  21.                 }
  22.  
  23.                 public void onAnimationRepeat(Animation anim) {
  24.  
  25.                        
  26.  
  27.                 }
  28.  
  29.         });
  30.  
  31.         scaleAnim.setFillAfter(true);
  32.  
  33.         scaleAnim.setDuration(700);
  34.  
  35.         scaleAnim.setInterpolator(i);
  36.  
  37.         img.startAnimation(scaleAnim);
  38.  
  39.  
  40.  
  41. // cX and cY is where I use the the my ImageView's onTouchListener to get MotionEvent's getX() and getY().
  42.  
  43. // code ends here.
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Thanks for any help!
emotioner
Freshman
Freshman
 
Posts: 2
Joined: Sun Jun 28, 2009 4:37 am

Top

Postby emotioner » Tue Jun 30, 2009 10:20 pm

Ok. I guess I kinda nailed it down to this problem: I have to map the touch point into the new matrix coordinate space since each time a new transformation is applied to the canvas to make the scale stick. And I don't know how to achieve this using the Android graphics API.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. // Snippet of my custom ImageView
  3.  
  4. @Override
  5.  
  6.         public void onDraw(Canvas canvas) {
  7.  
  8.                 Drawable dr = getDrawable();
  9.  
  10.                 if(dr != null)
  11.  
  12.                 {
  13.  
  14.                         Matrix m = canvas.getMatrix();
  15.  
  16.                         // cX, cY is the MotionEvent.getX/getY()
  17.  
  18.                         // I will need to figure out how to map this point into the existing matrix coordinate before restore it.
  19.  
  20.                         m.postScale(sX, sY, cX, cY);
  21.  
  22.                         canvas.setMatrix(m);
  23.  
  24.                         dr.draw(canvas);
  25.  
  26.                 }
  27.  
  28.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


I apologize for my maths if this looks rather ignorant. Please let me know if I am heading towards the right direction. Thanks.
emotioner
Freshman
Freshman
 
Posts: 2
Joined: Sun Jun 28, 2009 4:37 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests