开发者

Is there a way in android to get the area (a collection of points) of my finger

Is there a way in android to get the area (a collection of points) of my finger when i touch the screen. Usually, the return is one point location. I need to get the several points w开发者_如何学编程hich can represent the area of my touching. Any one knows? Thnaks


Just use View class's onTouchEvent() or implements OnTouchListener in your activity and get the X and Y co-ordinates like,

This is View class's OnTouchEvent()..

 @Override
 public boolean onTouchEvent(MotionEvent ev) {

  final int action = ev.getAction();
  switch (action & MotionEvent.ACTION_MASK) {


  case MotionEvent.ACTION_DOWN: {
     float x = ev.getX();
     float y = ev.getY();

     break;
  }

  case MotionEvent.ACTION_MOVE: {

   float mLastTouchX = x;
   float mLastTouchY = y;

    break;
}

  case MotionEvent.ACTION_UP: {
    break;
  }

  case MotionEvent.ACTION_CANCEL: {
    break;
  }

  case MotionEvent.ACTION_POINTER_UP: {

    break;
  }
  }

 return true;
 }

EDIT:

@Override
public void onCreate(Bundle savedInstanceState)
 {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textView = (TextView)findViewById(R.id.textView);
// this is the view on which you will listen for touch events
final View touchView = findViewById(R.id.touchView);
touchView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        textView.setText("Touch coordinates : " +
            String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
            return true;
    }
});
}

For more details Android - View.


Does it have to be the real shape of the finger? Otherwise you could calculate a circle around the center of the touch.


I believe this is not possible in the touch's coordinate along with it's area. It's natively unsupported by Android API.

Ref:

http://developer.android.com/guide/topics/ui/ui-events.html

http://developer.android.com/reference/android/gesture/package-summary.html


Unfortunately not. I ran in to this a while ago - you could try normalising the data over several 'frames'. May be worth trying to figure out why you need an exact point, or set of points, and find another way of doing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜