Note that there are some explanatory texts on larger screens.

plurals
  1. POsome problems about Multitouch
    primarykey
    data
    text
    <p>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.</p> <pre><code>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 &gt; 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 &lt; 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); } } </code></pre> <p>`</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload