下面是代碼示例:機器人onInterceptTouchEvent()的問題
public class SwipeRelativeLayout extends RelativeLayout {
private String TAG = "SwipedListView";
private MotionEvent previous = null;
private MotionEvent start = null;
public SwipeRelativeLayout(Context context) {
super(context);
}
public SwipeRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
String eventType = "";
switch (action)
{
case MotionEvent.ACTION_CANCEL:
{
eventType = "ACTION_CANCEL";
} break;
case MotionEvent.ACTION_DOWN:
{
eventType = "ACTION_DOWN";
} break;
case MotionEvent.ACTION_UP:
{
eventType = "ACTION_UP";
} break;
case MotionEvent.ACTION_MOVE:
{
eventType = "ACTION_MOVE";
} break;
}
Log.e(TAG, "onInterceptTouchEvent() Type = " + eventType + " X = " + Float.toString(ev.getRawX()) + " Y = " + Float.toString(ev.getRawY()));
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction() ;
String eventType = "";
switch (action)
{
case MotionEvent.ACTION_CANCEL:
{
eventType = "ACTION_CANCEL";
} break;
case MotionEvent.ACTION_DOWN:
{
eventType = "ACTION_DOWN";
} break;
case MotionEvent.ACTION_UP:
{
eventType = "ACTION_UP";
} break;
case MotionEvent.ACTION_MOVE:
{
eventType = "ACTION_MOVE";
} break;
}
Log.e(TAG, "onTouchEvent() Type = " + eventType + " X = " + Float.toString(event.getRawX()) + " Y = " + Float.toString(event.getRawY()));
return false;
}
}
有人能解釋一下,爲什麼我可以看到onle ACTION_DOWN事件到onInterceptTouchEvent()? 如已在developers.android.com
在3點告誡,只要你從這個功能,每個以下事件返回false(截至及包括最後上)將首先在這裏交付和然後到目標的onTouchEvent()。
我做了這個,但還是老樣子看不到事件到onInterceptTouchEvent(),除了ACTION_DOWN
即使你感到沮喪,你問題的語氣也需要專業。其他任何事情都不合適,並會降低獲得你想要的答案的可能性。 – Flexo
抱歉,對於標題,但andriod中的觸摸事件是複雜的,特別是onIntercept()。在www的android中沒有關於觸摸處理的明確解釋,即使在developers.android.com –
latto,thx的答案。不,這部分清楚。 –