android.view.MotionEvent.getRawX()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中android.view.MotionEvent.getRawX()方法的一些代码示例,展示了MotionEvent.getRawX()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.getRawX()方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:getRawX

MotionEvent.getRawX介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

editComment.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
     final int DRAWABLE_LEFT = 0;
     final int DRAWABLE_TOP = 1;
     final int DRAWABLE_RIGHT = 2;
     final int DRAWABLE_BOTTOM = 3;
     if(event.getAction() == MotionEvent.ACTION_UP) {
       if(event.getRawX() >= (editComment.getRight() - editComment.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
         // your action here
        return true;
       }
     }
     return false;
   }
 });

代码示例来源:origin: GitLqr/LQRWeChat

private boolean isCancelled(View view, MotionEvent event) {
  int[] location = new int[2];
  view.getLocationOnScreen(location);
  if (event.getRawX() < location[0] || event.getRawX() > location[0] + view.getWidth()
      || event.getRawY() < location[1] - 40) {
    return true;
  }
  return false;
}

代码示例来源:origin: stackoverflow.com

float dX, dY;

@Override
public boolean onTouch(View view, MotionEvent event) {

  switch (event.getAction()) {

    case MotionEvent.ACTION_DOWN:

      dX = view.getX() - event.getRawX();
      dY = view.getY() - event.getRawY();
      break;

    case MotionEvent.ACTION_MOVE:

      view.animate()
          .x(event.getRawX() + dX)
          .y(event.getRawY() + dY)
          .setDuration(0)
          .start();
      break;
    default:
      return false;
  }
  return true;
}

代码示例来源:origin: aa112901/remusic

@Override  
public boolean onTouch(View v, MotionEvent event) {  
  switch (event.getAction()) {  
  case MotionEvent.ACTION_DOWN:  
    downX = tempX = (int) event.getRawX();  
    downY = (int) event.getRawY();  
    break;  
  case MotionEvent.ACTION_MOVE:  
    int moveX = (int) event.getRawX();  
    int deltaX = tempX - moveX;  
    tempX = moveX;  
    if (Math.abs(moveX - downX) > mTouchSlop  
        && Math.abs((int) event.getRawY() - downY) < mTouchSlop) {  
      isSilding = true;

代码示例来源:origin: janishar/PlaceHolderView

xStart = event.getRawX();
  x = event.getRawX();
  activePointerId = event.getPointerId(0);
  resetDone = false;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
  case MotionEvent.ACTION_DOWN:
    break;
  case MotionEvent.ACTION_MOVE:
    if(!resetDone && event.findPointerIndex(activePointerId) != SwipeDecor.PRIMITIVE_NULL) {
      x = event.getRawX();
      FrameLayout.LayoutParams layoutParamsTemp = (FrameLayout.LayoutParams) v.getLayoutParams();
      layoutParamsTemp.leftMargin = (int) (x - dx);

代码示例来源:origin: burhanrashid52/PhotoEditor

int action = event.getAction();
int x = (int) event.getRawX();
int y = (int) event.getRawY();
    mPrevX = event.getX();
    mPrevY = event.getY();
    mPrevRawX = event.getRawX();
    mPrevRawY = event.getRawY();
    mActivePointerId = event.getPointerId(0);
    if (deleteView != null) {

代码示例来源:origin: daimajia/AndroidSwipeLayout

@Override
public boolean onTouchEvent(MotionEvent event) {
  if (!isSwipeEnabled()) return super.onTouchEvent(event);
  int action = event.getActionMasked();
  gestureDetector.onTouchEvent(event);
  switch (action) {
    case MotionEvent.ACTION_DOWN:
      mDragHelper.processTouchEvent(event);
      sX = event.getRawX();
      sY = event.getRawY();
    case MotionEvent.ACTION_MOVE: {
      //the drag state and the direction are already judged at onInterceptTouchEvent
      checkCanDrag(event);
      if (mIsBeingDragged) {
        getParent().requestDisallowInterceptTouchEvent(true);
        mDragHelper.processTouchEvent(event);
      }
      break;
    }
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
      mIsBeingDragged = false;
      mDragHelper.processTouchEvent(event);
      break;
    default://handle other action, such as ACTION_POINTER_DOWN/UP
      mDragHelper.processTouchEvent(event);
  }
  return super.onTouchEvent(event) || mIsBeingDragged || action == MotionEvent.ACTION_DOWN;
}

代码示例来源:origin: stackoverflow.com

int[] listViewCoords = new int[2];
mListView.getLocationOnScreen(listViewCoords);
int x = (int) motionEvent.getRawX() - listViewCoords[0];
int y = (int) motionEvent.getRawY() - listViewCoords[1];
View child;
for (int i = 0; i < childCount; i++) {
  mDownX = motionEvent.getRawX();
  mDownPosition = mListView.getPositionForView(mDownView);
float deltaX = motionEvent.getRawX() - mDownX;
mVelocityTracker.addMovement(motionEvent);
mVelocityTracker.computeCurrentVelocity(500); // 1000 by defaut but it was too much
float deltaX = motionEvent.getRawX() - mDownX;
if (Math.abs(deltaX) > mSlop) {
  mSwiping = true;

代码示例来源:origin: stackoverflow.com

viewB.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {}
 });
 viewB.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
     int x = (int)event.getRawX();
     int y = (int)event.getRawY();
     if(event.getAction() == MotionEvent.ACTION_UP){
       if(isViewInBounds(viewA, x, y))
         viewA.dispatchTouchEvent(event);
       else if(isViewInBounds(viewB, x, y)){
         Log.d(TAG, "onTouch ViewB");
         //Here goes code to execute on onTouch ViewB
       }
     }
     // Further touch is not handled
     return false;
   }
 });

代码示例来源:origin: stackoverflow.com

editComment.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
     final int DRAWABLE_LEFT = 0;
     final int DRAWABLE_TOP = 1;
     final int DRAWABLE_RIGHT = 2;
     final int DRAWABLE_BOTTOM = 3;
     if(event.getAction() == MotionEvent.ACTION_UP) {
       if(event.getRawX() >= (editComment.getRight() - editComment.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
         // your action here
        return true;
       }
     }
     return false;
   }
 });

代码示例来源:origin: janishar/PlaceHolderView

pointerStartingPoint.set(event.getRawX(), event.getRawY());
  pointerCurrentPoint.set(event.getRawX(), event.getRawY());
  activePointerId = event.getPointerId(0);
  resetDone = false;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
  case MotionEvent.ACTION_DOWN:
    break;
  case MotionEvent.ACTION_MOVE:
    if(!resetDone && event.findPointerIndex(activePointerId) != SwipeDecor.PRIMITIVE_NULL) {
      pointerCurrentPoint.set(event.getRawX(), event.getRawY());
      FrameLayout.LayoutParams layoutParamsTemp = (FrameLayout.LayoutParams) v.getLayoutParams();
      layoutParamsTemp.topMargin = (int) (pointerCurrentPoint.y - dy);

代码示例来源:origin: stackoverflow.com

protected Point getRelativePosition(View v, MotionEvent event) {
  int[] location = new int[2];
  v.getLocationOnScreen(location);
  float screenX = event.getRawX();
  float screenY = event.getRawY();
  float viewX = screenX - location[0];
  float viewY = screenY - location[1];
  return new Point((int) viewX, (int) viewY);
}

代码示例来源:origin: stackoverflow.com

int[] listViewCoords = new int[2];
getLocationOnScreen(listViewCoords);
int x = (int)event.getRawX() - listViewCoords[0];
int y = (int)event.getRawY() - listViewCoords[1];
View child;
for (int i = 0; i < childCount; i++) {

代码示例来源:origin: stackoverflow.com

viewA.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {}
 });
 viewA.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
     int x = (int)event.getRawX();
     int y = (int)event.getRawY();
     if(event.getAction() == MotionEvent.ACTION_UP){
       if(isViewInBounds(viewB, x, y))
         viewB.dispatchTouchEvent(event);
       else if(isViewInBounds(viewA, x, y)){
         Log.d(TAG, "onTouch ViewA");
         //Here goes code to execute on onTouch ViewA
       }
     }
     // Further touch is not handled
     return false;
   }
 });

代码示例来源:origin: mcxtzhang/SwipeDelMenuLayout

switch (ev.getAction()) {
    if (Math.abs(ev.getRawX() - mFirstP.x) > mScaleTouchSlop) {
      return true;

代码示例来源:origin: janishar/PlaceHolderView

pointerStartingPoint.set(event.getRawX(), event.getRawY());
  pointerCurrentPoint.set(event.getRawX(), event.getRawY());
  activePointerId = event.getPointerId(0);
  resetDone = false;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
  case MotionEvent.ACTION_DOWN:
    break;
  case MotionEvent.ACTION_MOVE:
    if (!resetDone && event.findPointerIndex(activePointerId) != SwipeDecor.PRIMITIVE_NULL) {
      pointerCurrentPoint.set(event.getRawX(), event.getRawY());
      FrameLayout.LayoutParams layoutParamsTemp = (FrameLayout.LayoutParams) v.getLayoutParams();
      layoutParamsTemp.topMargin = (int) (pointerCurrentPoint.y - dy);

代码示例来源:origin: gzu-liyujiang/AndroidPicker

private boolean isEventWithinView(MotionEvent e, View child) {
    Rect viewRect = new Rect();
    int[] childPosition = new int[2];
    child.getLocationOnScreen(childPosition);
    int left = childPosition[0];
    int right = left + child.getWidth();
    int top = childPosition[1];
    int bottom = top + child.getHeight();
    viewRect.set(left, top, right, bottom);
    return viewRect.contains((int) e.getRawX(), (int) e.getRawY());
  }
};

代码示例来源:origin: xiaojianglaile/Calendar

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
  switch (ev.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
      mDownPosition[0] = ev.getRawX();
      mDownPosition[1] = ev.getRawY();
      mGestureDetector.onTouchEvent(ev);
      break;
  }
  return super.dispatchTouchEvent(ev);
}

代码示例来源:origin: jiajunhui/PlayerBase

public boolean onInterceptTouchEvent(MotionEvent ev) {
  if(!mDragEnable)
    return false;
  switch (ev.getAction()){
    case MotionEvent.ACTION_DOWN:
      mDownX = ev.getRawX();
      mDownY = ev.getRawY();
      break;
    case MotionEvent.ACTION_MOVE:
      if(Math.abs(ev.getRawX() - mDownX) > MIN_MOVE_DISTANCE
          || Math.abs(ev.getRawY() - mDownY) > MIN_MOVE_DISTANCE){
        return true;
      }
      return false;
  }
  return false;
}

代码示例来源:origin: jdsjlzx/LRecyclerView

switch (ev.getAction()) {
    if (Math.abs(ev.getRawX() - mFirstP.x) > mScaleTouchSlop) {
      return true;

相关文章