Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:42:41+00:00 2026-06-15T13:42:41+00:00

I have written an app that can drag an image and then spring back

  • 0

I have written an app that can drag an image and then spring back the image. But the speed of spring back is too fast. I have tried but can’t find a way to slow down it.

How can I control the speed of this?

public class CustomViewActivity extends Activity {

    float mx,my;
    ImageView switcherView;
    Bitmap bitmap;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_view);

        switcherView = (ImageView) this.findViewById(R.id.img);  
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.kh06);
        switcherView.setImageBitmap(bitmap);

        switcherView.setOnTouchListener(new View.OnTouchListener() {   
            public boolean onTouch(View arg0, MotionEvent event) {  
                float curX, curY;  
              //System.out.println(switcherView.getScrollX()+"--------view axis-----");
                switch (event.getAction()) {        
                    case MotionEvent.ACTION_DOWN:  
                        mx = event.getX();  
                        break;  
                    case MotionEvent.ACTION_MOVE:  
                        curX = event.getX();    
                        switcherView.scrollBy((int) (mx - curX), 0);  
                        mx = curX;  
                        break;  
                    case MotionEvent.ACTION_UP:                                                
                        switcherView.scrollTo(0, 0);
                        break;  
                }  
                return true;  
            }  
        });
    }
  }

scaleType of image is the center,the image hasn’t been zoomed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:42:43+00:00Added an answer on June 15, 2026 at 1:42 pm

    You need to write some code here

     case MotionEvent.ACTION_UP:                                                
        switcherView.scrollTo(0, 0);
        break; 
    

    Instead of directly moving back to 0,0 put a for loop and go to 0,0 from current position in many iteration. some thing like this.

     case MotionEvent.ACTION_UP:                                                
        new Timer().schedule(new TimerTask() {
    
                        @Override
                        public void run() {
    
                            MainActivity.this.runOnUiThread(new Runnable() {
    
                                public void run() {
                                    myImage.scrollTo((int) mx, 0);
                                    myImage.invalidate();
    
                                }
                            });
    
                            if (mx > 0) {
                                mx -= 1;
                            } else {
                                cancel();
                            }
    
    
    
                        }
                    }, 100,10);
    

    Update
    This is code is working if you drag from right to left but when drag from left to right not working properly so correct it your self.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an iPhone app that uses the iPhone's relative GPS location. I
I have written a C# app that runs constantly in a loop and several
I have written a small app that puts my bluetooth in discoverable mode for
I have written a BlackBerry app that RSA encrypts a message using PKCS1FormatterEngine. This
I have written a small chat app that uses mysql + php to facilitate
I have written an GWT app and a static Intro page that introduces the
I am learning flex and have written a little app with a TextArea that
I have a TCP server app that is written in C#. I accept TCP
I have a legacy intranet web app that was written for IE7 and contains
We have an app that needs to access network resources. It's written in VB.Net.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.