cannt scroll imageview right and down

Put your problem here if it does not fit any of the other categories.

cannt scroll imageview right and down

Postby ollie » Sat May 03, 2008 10:28 am

hi,everyone!
I add onTouchEvent method to ImageSwitcher of API Demo, and i'd like to scroll the image in this method.But the image cannt be scrolled right and down from its original place.The following is my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  private float mx,my;
  2.  
  3.     @Override
  4.  
  5.     public boolean onTouchEvent(MotionEvent event)
  6.  
  7.     {
  8.  
  9.         ImageView switcherView = (ImageView)mSwitcher.getCurrentView();
  10.  
  11.         float curX,curY;
  12.  
  13.         switch(event.getAction())
  14.  
  15.         {
  16.  
  17.            case MotionEvent.ACTION_DOWN :
  18.  
  19.                    mx = event.getX();
  20.  
  21.                    my = event.getY();
  22.  
  23.                    break;
  24.  
  25.           case MotionEvent.ACTION_MOVE :
  26.  
  27.                    curX = event.getX();
  28.  
  29.                    curY = event.getY();
  30.  
  31.                    switcherView.scrollBy((int)(mx - curX),(int)(my - curY));
  32.  
  33.                    mx = curX;
  34.  
  35.                    my = curY;
  36.  
  37.                    break;
  38.  
  39.            case MotionEvent.ACTION_UP :
  40.  
  41.                    curX = event.getX();
  42.  
  43.                    curY = event.getY();
  44.  
  45.                    switcherView.scrollBy((int)(mx - curX),(int)(my - curY));
  46.  
  47.                    break;
  48.  
  49.         }      
  50.  
  51.         return super.onTouchEvent(event);
  52.  
  53.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
ollie
Freshman
Freshman
 
Posts: 4
Joined: Tue Mar 25, 2008 1:41 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Adsense [Bot], Yahoo [Bot] and 21 guests