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 6812551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:27:45+00:00 2026-05-26T20:27:45+00:00

I want to judge the distance between two points when I touch the screen

  • 0

I want to judge the distance between two points when I touch the screen and move my two fingers.I don’t konw my calculation method is right or wrong.If you have the true method,please tell me.Thanks very much.

public class MyMultitouch implements OnTouchListener, OnGestureListener{
private GestureDetector mGestureDetector;
private View view;
private LinearLayout _first_linearlayout;
private LinearLayout _middle_linearlayout;
private float beforeLenght1,beforeLenght2;
private float afterLenght1,afterLenght2;
private float gapLenght,gapLenght1,gapLenght2;

public MyMultitouch(View view){
    this.mGestureDetector = new GestureDetector(this);
    this.view = view;
    mGestureDetector.setIsLongpressEnabled(true);
}

@Override
public boolean onDown(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {

    float moveX1 = e1.getX(1) - e1.getX(0);
    float moveY1 = e1.getY(1) - e1.getY(0);

    float moveX2 = e2.getX(1) - e2.getX(0);
    float moveY2 = e2.getY(1) - e2.getY(0);

    switch (e1.getAction()) {
    case MotionEvent.ACTION_DOWN:
        beforeLenght1 = (float) Math.sqrt((moveX1 * moveX1)
                + (moveY1 * moveY1));
        beforeLenght2 = (float) Math.sqrt((moveX2 * moveX2)
                + (moveY2 * moveY2));
        break;
    case MotionEvent.ACTION_MOVE:
        afterLenght1 = (float) Math.sqrt((moveX1 * moveX1)
                + (moveY1 * moveY1));
        afterLenght2 = (float) Math.sqrt((moveX2 * moveX2)
                + (moveY2 * moveY2));
        gapLenght1 = afterLenght1 - beforeLenght1;
        gapLenght2 = afterLenght2 - beforeLenght2;
        gapLenght = gapLenght2 - gapLenght1;
    }
    if (gapLenght > 0) {
        _first_linearlayout = (LinearLayout)view.findViewById(R.id.first_linearlayout);
        _middle_linearlayout = (LinearLayout)view.findViewById(R.id.middle_linearlayout);
        _first_linearlayout.setVisibility(View.GONE);
        _middle_linearlayout.setVisibility(View.GONE);
    }
    if (gapLenght < 0) {
        _first_linearlayout = (LinearLayout)view.findViewById(R.id.first_linearlayout);
        _middle_linearlayout = (LinearLayout)view.findViewById(R.id.middle_linearlayout);
        _first_linearlayout.setVisibility(View.VISIBLE);
        _middle_linearlayout.setVisibility(View.VISIBLE);
    }
    return true;
}
@Override
public void onLongPress(MotionEvent e) {
    // TODO Auto-generated method stub

}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
        float distanceY) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public void onShowPress(MotionEvent e) {
    // TODO Auto-generated method stub

}
@Override
public boolean onSingleTapUp(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
    // TODO Auto-generated method stub
    return mGestureDetector.onTouchEvent(arg1);
}
}

`

  • 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-05-26T20:27:46+00:00Added an answer on May 26, 2026 at 8:27 pm

    You could use spacing method in this section of the How to use Multi-touch in Android 2 article.

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

Sidebar

Related Questions

I want make a screen width judge, when screen width is bigger than 1024px
I'm new to Objective-C, so please don't judge me too much. I was wondering:
I want use regex to make a judge, if some sring's structure is made
I have a path, for example, named /my/path/test/mytestpath , and I want to judge
I'm participating in online judge contests and I want to test my code with
I want insert some articles. I want make a judge first, if the image
I have a settlement, I want to judge if the return_service_date is today, how
In anyway, I want make a judge, if div's id match something, then add
I'm extremely new to using jQuery/JavaScript, so please don't judge me if this is
I want to make a judge, if checkbox value = 2, selected. But now

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.