本文整理汇总了Java中android.view.View.dispatchTouchEvent方法的典型用法代码示例。如果您正苦于以下问题:Java View.dispatchTouchEvent方法的具体用法?Java View.dispatchTouchEvent怎么用?Java View.dispatchTouchEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.dispatchTouchEvent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: duplicateTouchEventForChildren
import android.view.View; //导入方法依赖的package包/类
/**
* Duplicate touch events to child views.
* We want to dispatch a down motion event and the move events to
* child views, but calling dispatchTouchEvent() causes StackOverflowError.
* Therefore we do it manually.
*
* @param ev motion event to be passed to children
* @param pendingEvents pending events like ACTION_DOWN. This will be passed to the children before ev
*/
private void duplicateTouchEventForChildren(MotionEvent ev, MotionEvent... pendingEvents) {
if (ev == null) {
return;
}
for (int i = getChildCount() - 1; 0 <= i; i--) {
View childView = getChildAt(i);
if (childView != null) {
Rect childRect = new Rect();
childView.getHitRect(childRect);
MotionEvent event = MotionEvent.obtainNoHistory(ev);
if (!childRect.contains((int) event.getX(), (int) event.getY())) {
continue;
}
float offsetX = -childView.getLeft();
float offsetY = -childView.getTop();
boolean consumed = false;
if (pendingEvents != null) {
for (MotionEvent pe : pendingEvents) {
if (pe != null) {
MotionEvent peAdjusted = MotionEvent.obtainNoHistory(pe);
peAdjusted.offsetLocation(offsetX, offsetY);
consumed |= childView.dispatchTouchEvent(peAdjusted);
}
}
}
event.offsetLocation(offsetX, offsetY);
consumed |= childView.dispatchTouchEvent(event);
if (consumed) {
break;
}
}
}
}
示例2: onTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
int width = getWidth() / getChildCount();
int height = getHeight();
int count = getChildCount();
float eventX = event.getX();
if (eventX < width) {
getChildAt(0).dispatchTouchEvent(event);
} else if (eventX > width && eventX < 2 * width) {
float eventY = event.getY();
if (eventY < height / 2) {
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
child.dispatchTouchEvent(event);
}
} else {
getChildAt(1).dispatchTouchEvent(event);
}
} else if (eventX > 2 * width) {
getChildAt(2).dispatchTouchEvent(event);
}
return true;
}
示例3: onTouch
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
final int actionMasked = motionEvent.getActionMasked();
if (actionMasked == MotionEvent.ACTION_DOWN) {
if (view instanceof ViewGroup) {
mInitialTouchTarget = findNearestChild((ViewGroup) view,
(int) motionEvent.getX(), (int) motionEvent.getY());
} else {
mInitialTouchTarget = null;
}
}
final View child = mInitialTouchTarget;
if (child == null) {
return false;
}
final float offsetX = view.getScrollX() - child.getLeft();
final float offsetY = view.getScrollY() - child.getTop();
motionEvent.offsetLocation(offsetX, offsetY);
final boolean handled = child.dispatchTouchEvent(motionEvent);
motionEvent.offsetLocation(-offsetX, -offsetY);
if (actionMasked == MotionEvent.ACTION_UP
|| actionMasked == MotionEvent.ACTION_CANCEL) {
mInitialTouchTarget = null;
}
return handled;
}
示例4: dispatchTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
try {
child.dispatchTouchEvent(ev);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
示例5: onTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(CoordinatorLayout parent, View child, MotionEvent ev) {
if (!mShouldIntercept) return false;
ev.offsetLocation(-child.getX(), -child.getY());
child.dispatchTouchEvent(ev);
return true;
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:8,代码来源:CompositorViewHolderBehavior.java
示例6: propagateEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean propagateEvent(MotionEvent e) {
if (e == null) return false;
View view = getActiveLayout().getViewForInteraction();
if (view == null) return false;
e.offsetLocation(-view.getLeft(), -view.getTop());
return view.dispatchTouchEvent(e);
}
示例7: onTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
updateSourcePartial();
// The logic below is mostly copied from the parent class, since we
// can't update private mBounds variable.
// http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;
// f=core/java/android/view/TouchDelegate.java;hb=eclair#l98
final Rect sourcePartial = mSourcePartial;
final View target = mTarget;
int x = (int)event.getX();
int y = (int)event.getY();
boolean sendToDelegate = false;
boolean hit = true;
boolean handled = false;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (sourcePartial.contains(x, y)) {
mDelegateTargeted = true;
sendToDelegate = true;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_MOVE:
sendToDelegate = mDelegateTargeted;
if (sendToDelegate) {
if (!sourcePartial.contains(x, y)) {
hit = false;
}
}
break;
case MotionEvent.ACTION_CANCEL:
sendToDelegate = mDelegateTargeted;
mDelegateTargeted = false;
break;
}
if (sendToDelegate) {
if (hit) {
event.setLocation(target.getWidth() / 2, target.getHeight() / 2);
} else {
event.setLocation(-1, -1);
}
handled = target.dispatchTouchEvent(event);
}
return handled;
}
示例8: adjustDownMotion
import android.view.View; //导入方法依赖的package包/类
/**
* fake a ACTION_DOWN to adjust child's motion track
*
* @param v
* @param e
*/
private void adjustDownMotion(View v, MotionEvent e) {
MotionEvent fakeDownEvent = MotionEvent.obtain(e);
fakeDownEvent.setAction(MotionEvent.ACTION_DOWN);
v.dispatchTouchEvent(fakeDownEvent);
}