本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}