我在尝试生成一个 MotionEvent.ACTION_UP 时遇到了问题,可能是初学者的错误。
在 LogCat 中,我只看到 ACTION_MOVE 事件(一个整数值为3)。我也能看到 X/Y 坐标。没有 ACTION_DOWN 和 ACTION_UP。
我已经到处寻找解决方案。我在论坛上找到了一个与我的问题相似的问题,但没有提出解决方案: http://groups.google.com/group/android-developers/browse_thread/thread/9a9c23e40f02c134/bf12b89561f204ad?lnk=gst&q=ACTION_UP#bf12b89561f204ad
这是我的代码:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.webkit.WebView;
public class Brand extends Activity {
public WebView webview;
public float currentXPosition;
public float currentYPosition;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webview = new WebView(this);
setContentView(webview);
webview.loadUrl("file:///android_asset/Brand.html");
}
@Override
public boolean onTouchEvent(MotionEvent me) {
int action = me.getAction();
currentXPosition = me.getX();
currentYPosition = me.getY();
Log.v("MotionEvent", "Action = " + action);
Log.v("MotionEvent", "X = " + currentXPosition + "Y = " + currentYPosition);
if (action == MotionEvent.ACTION_MOVE) {
// do something
}
if (action == MotionEvent.ACTION_UP) {
// do something
}
return true;
}
}