當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.getRawX方法代碼示例

本文整理匯總了Java中android.view.MotionEvent.getRawX方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.getRawX方法的具體用法?Java MotionEvent.getRawX怎麽用?Java MotionEvent.getRawX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.getRawX方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    int action = e.getAction();
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            downX = (int) e.getRawX();
            downY = (int) e.getRawY();
            break;
        case MotionEvent.ACTION_MOVE:
            int moveY = (int) e.getRawY();
            if (Math.abs(moveY - downY) > mTouchSlop) {
                return true;
            }
    }
    return super.onInterceptTouchEvent(e);
}
 
開發者ID:yangchong211,項目名稱:YCUtils,代碼行數:17,代碼來源:NoNestedScrollview.java

示例2: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    final int X = (int) event.getRawX();
    final int Y = (int) event.getRawY();
    switch (event.getAction()) {
        case MotionEvent.ACTION_UP:
            firstTouch = true;
            break;
        case MotionEvent.ACTION_MOVE:
            if (firstTouch) {
                floatX = (int) event.getX();
                floatY = (int) (event.getY() + WindowUtil.getStatusBarHeight(getContext()));
                firstTouch = false;
            }
            mParams.x = X - floatX;
            mParams.y = Y - floatY;
            mWindowManager.updateViewLayout(this, mParams);
            break;
    }
    return super.onTouchEvent(event);
}
 
開發者ID:dueeeke,項目名稱:dkplayer,代碼行數:22,代碼來源:FloatView.java

示例3: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
	x = event.getRawX();
	y = event.getRawY();
	switch (event.getAction()) {
	case MotionEvent.ACTION_DOWN:
		touchX = event.getX();
		touchY = event.getY();
		break;
	case MotionEvent.ACTION_MOVE:
		if (dragEnabled) {
			updateViewPostion();
		}
		break;
	case MotionEvent.ACTION_CANCEL:
	case MotionEvent.ACTION_UP:
		touchX = touchY = 0;
		dragEnabled = false;
		break;
	default:
		break;
	}
	return super.onTouchEvent(event);
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:25,代碼來源:LinphoneOverlay.java

示例4: getClearListener

import android.view.MotionEvent; //導入方法依賴的package包/類
@NonNull
private View.OnTouchListener getClearListener(final EditText editText) {
    return new View.OnTouchListener() {
        final int DRAWABLE_LEFT = 0;
        final int DRAWABLE_TOP = 1;
        final int DRAWABLE_RIGHT = 2;
        final int DRAWABLE_BOTTOM = 3;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                int leftEdgeOfRightDrawable = editText.getRight()
                        - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width();
                // when EditBox has padding, adjust leftEdge like
                // leftEdgeOfRightDrawable -= getResources().getDimension(R.dimen.edittext_padding_left_right);
                if (event.getRawX() >= leftEdgeOfRightDrawable) {
                    // clicked on clear icon
                    editText.setText("");
                    editText.clearFocus();
                    return true;
                }
            }
            return false;
        }
    };
}
 
開發者ID:aliumujib,項目名稱:Nibo,代碼行數:27,代碼來源:NiboOriginDestinationPickerFragment.java

示例5: inRangeOfView

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    if (view.getVisibility() != View.VISIBLE) {
        return false;
    }
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x
            || ev.getRawX() > (x + view.getWidth())
            || ev.getRawY() < y
            || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:17,代碼來源:SimpleClickListener.java

示例6: inRangeOfView

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    if (view.getVisibility()!= View.VISIBLE){
        return false;
    }
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x
            || ev.getRawX() > (x + view.getWidth())
            || ev.getRawY() < y
            || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:SimpleClickListener.java

示例7: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
    switch (motionEvent.getAction()) {
        case 0:
            this.downY = motionEvent.getRawY();
            this.downX = motionEvent.getRawX();
            this.downTime = motionEvent.getEventTime();
            break;
        case 1:
            this.upTime = motionEvent.getEventTime();
            this.upX = motionEvent.getRawX();
            this.upY = motionEvent.getRawY();
            this.deltaTime = this.upTime - this.downTime;
            if (this.downY - this.upY >= ((float) DensityUtil.dip2px(getContext(), (float)
                    this.DEFAULT_SLIDING))) {
                if (this.onSlidingUpListener != null) {
                    this.onSlidingUpListener.onSlidingUp();
                }
                return true;
            }
            break;
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:24,代碼來源:HomePopSlidingLayout.java

示例8: onTouch

import android.view.MotionEvent; //導入方法依賴的package包/類
private boolean onTouch(View v, MotionEvent event) {

        switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                dX = v.getX() - event.getRawX();
                dY = v.getY() - event.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                v.setX(event.getRawX() + dX);
                v.setY(event.getRawY() + dY);
                break;
            case MotionEvent.ACTION_UP:
                break;
            default:
                return false;
        }

        return true;
    }
 
開發者ID:hulab,項目名稱:debugkit,代碼行數:21,代碼來源:DevToolFragment.java

示例9: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean onInterceptTouchEvent(MotionEvent event) {
    int action = MotionEventCompat.getActionMasked(event);

    float x = event.getRawX();
    float y = event.getRawY();

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        reset(initialMotionX, initialMotionY);
        return false;
    }

    if (action != MotionEvent.ACTION_DOWN) {
        if (isBeingDragged) {
            return true;
        }
    }

    switch (action) {
        case MotionEvent.ACTION_DOWN:
            initialMotionX = lastMotionX = x;
            initialMotionY = lastMotionY = y;
            break;
        case MotionEvent.ACTION_MOVE:
            final float xDiff = Math.abs(x - initialMotionX);
            final float yDiff = Math.abs(y - initialMotionY);
            if (xDiff > touchSlop && xDiff > yDiff) {
                isBeingDragged = true;
                //direction horizon
                direction = DIRECTION_LEFT_RIGHT;
            } else if (yDiff > touchSlop && yDiff > xDiff) {
                isBeingDragged = true;
                //direction vertical
                direction = DIRECTION_TOP_BOTTOM;
            }
            break;
    }
    return isBeingDragged;
}
 
開發者ID:mingdroid,項目名稱:SETransitionDemo,代碼行數:41,代碼來源:SwipeGestureDetector.java

示例10: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    //處理滑動的邏輯
    /**
     * 如何有滑動的效果?
     * View.scrollTo(x,y);
     * 		讓View相對於它初始的位置滾動一段距離。
     * View.scrollBy(x,y);
     * 		讓View相對於它現在的位置滾動一段距離。
     * 注意:上麵兩種方法都是滑動View裏麵的內容,即裏麵的所有子控件。
     *
     */
    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE:
            moveX = event.getRawX();
            int scrollDx = (int) (lastMoveX - moveX);
            Log.i(TAG , "~~~~moveX:"+moveX+", scrollDx:"+scrollDx+", lastMoveX:"+lastMoveX+", leftBound"+leftBound);
            //左邊界判斷,如果不斷拖拽到達了左邊界則拖拽就失效了
            if (getScrollX()+scrollDx < leftBound) {
                scrollTo(leftBound, 0);
                return true;
            } else if (getScrollX()+scrollDx+getWidth() > rightBound) {
                scrollTo(rightBound - getWidth(), 0);
                return true;
            }
            scrollBy(scrollDx, 0);
            lastMoveX = moveX;
            break;
        case MotionEvent.ACTION_UP:


            break;

        default:
            break;
    }
    return super.onTouchEvent(event);
}
 
開發者ID:AndryYu,項目名稱:EventDeliver,代碼行數:39,代碼來源:MyViewPager.java

示例11: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getRawX() >= range && getLeft() >= range) {
                LogUtil.e("中斷");
        } else {
                LogUtil.e("不中斷");
        }
        return ev.getRawX() >= range && getLeft() >= range;
}
 
開發者ID:HelloChenJinJun,項目名稱:TestChat,代碼行數:10,代碼來源:ContentView.java

示例12: dispatchTouchEventForDialog

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean dispatchTouchEventForDialog(MotionEvent ev, Dialog dialog, final boolean consumed,
                                           Activity activity, boolean needClearFocus) {
    if (ev.getAction() == MotionEvent.ACTION_UP
            && ev.getAction() != MotionEvent.ACTION_SCROLL) {
        final View view = dialog.getWindow().getCurrentFocus();
        if (view != null) {
            final View viewTmp;
            viewTmp = dialog.getWindow().getCurrentFocus();
            final View viewNew = viewTmp != null ? viewTmp : view;
            if (viewNew.equals(view)) {
                final Rect rect = new Rect();
                final int[] coordinates = new int[2];

                view.getLocationOnScreen(coordinates);
                rect.set(coordinates[0], coordinates[1], coordinates[0] + view.getWidth(), coordinates[1] + view.getHeight());

                final int x = (int) ev.getRawX();
                final int y = (int) ev.getRawY();

                if (rect.contains(x, y)) {
                    return consumed;
                }
            } else if (viewNew instanceof EditText) {
                return consumed;
            }
            hideKeyboard(view, activity);
            if (needClearFocus) {
                viewNew.clearFocus();
            }
            return consumed;
        }
    }
    return consumed;
}
 
開發者ID:Omega-R,項目名稱:OmegaKeyboard,代碼行數:35,代碼來源:AutoHideKeyboardHelper.java

示例13: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent ev)
{
	float rawX = ev.getRawX();
	float rawY = ev.getRawY();
	switch(ev.getAction())
	{
		case MotionEvent.ACTION_DOWN:
			float[] screenCoords = view.getScreenCoordsForPos(line, pos);
			dragX = screenCoords[0] - rawX;
			dragY = screenCoords[1] - rawY;
			dragging = true;
			return true;
		case MotionEvent.ACTION_MOVE:
			if(dragging)
			{
				float newScreenX = dragX + rawX;
				float newScreenY = dragY + rawY;
				int[] position = view.getPosForScreenCoords(newScreenX, newScreenY - yOffset);
				if(position != null)
				{
					line = position[0];
					pos = position[1];
					for(OnSelectionChangedListener listener : view.selectionChangedListeners)
						listener.onSelectionChanged();
					view.updateHandles();
				}
				return true;
			}
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL:
			if(dragging)
			{
				dragging = false;
				return true;
			}
	}
	return false;
}
 
開發者ID:mniip,項目名稱:bananapeel,代碼行數:40,代碼來源:SelectableScrollbackView.java

示例14: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:SwipeLayout.java

示例15: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
	public boolean onTouchEvent(MotionEvent event) {

		// If the bitmap was set, check the scale and gesture detectors
		if(mBitmap!=null){

			// Check the scale detector
			mScaleDetector.onTouchEvent( event );

			// Check the gesture detector
			if(!mScaleDetector.isInProgress())
				mGestureDetector.onTouchEvent( event );
		}

		switch (event.getAction()){
			case MotionEvent.ACTION_DOWN:
				// First, disable the Parent from intercepting the touch
				// event

				// fling
				x=(int)event.getRawX();
				y=(int)event.getRawY();
				time1=(long)System.currentTimeMillis();
//					Log.e("downtime",time1+"");
				break;
			case MotionEvent.ACTION_UP:
				// If the user has zoomed less than min scale, zoom back
				// to min scale

		}
		// Default case
		return true;
	}
 
開發者ID:lpy19930103,項目名稱:MinimalismJotter,代碼行數:34,代碼來源:ZoomableImageView.java


注:本文中的android.view.MotionEvent.getRawX方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。