android开发中,为什么OnTouch监听事件只监听到DOWN操作,没有监听到MOVE和UP操作?麻烦知道的告诉一下,谢谢
测试代码如下:packagecom.android.demo.demo;importandroid.app.Activity;importandroid.graphics...
测试代码如下:
package com.android.demo.demo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
public class Demo extends Activity implements OnTouchListener{
/** Called when the activity is first created. */
private LinearLayout layout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
layout=new LinearLayout(this);
layout.setBackgroundColor(Color.WHITE);
layout.setOnTouchListener(this);
setContentView(layout);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
int a=0;
a++;
break;
case MotionEvent.ACTION_UP:
int b=0;
b++;
break;
case MotionEvent.ACTION_MOVE:
int c=0;
c++;
break;
default:
break;
}
return false;
}
} 展开
package com.android.demo.demo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
public class Demo extends Activity implements OnTouchListener{
/** Called when the activity is first created. */
private LinearLayout layout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
layout=new LinearLayout(this);
layout.setBackgroundColor(Color.WHITE);
layout.setOnTouchListener(this);
setContentView(layout);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
int a=0;
a++;
break;
case MotionEvent.ACTION_UP:
int b=0;
b++;
break;
case MotionEvent.ACTION_MOVE:
int c=0;
c++;
break;
default:
break;
}
return false;
}
} 展开
2个回答
2010-12-27
展开全部
将return false改成return true;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询