我有一组 java 代码,我尝试检测用户的触摸手势。当用户进行简单的触摸/向下滑动等操作时,文本视图将显示用户当前所做的事情。但是,当我在模拟器上运行代码时,它只是一个显示 Hello World 的黑屏!当我触摸时,什么都没有显示..为什么会这样?附上代码。谢谢你的帮助...
package org.tp.iit.cds.BrailleTypeSend;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
import android.view.GestureDetector;
import android.widget.TextView;
import android.graphics.Color;
public class BrailleSend extends Activity implements OnGestureListener {
/** Called when the activity is first created. */
public LinearLayout main;
public TextView viewA;
public GestureDetector gestureScanner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gestureScanner = new GestureDetector(this);
main = new LinearLayout(this);
main.setBackgroundColor(Color.GRAY);
main.setLayoutParams(new LinearLayout.LayoutParams(320,480));
viewA = new TextView(this);
viewA.setBackgroundColor(Color.YELLOW);
viewA.setTextColor(Color.WHITE);
viewA.setTextSize(16);
viewA.setLayoutParams(new LinearLayout.LayoutParams(320,80));
main.addView(viewA);
setContentView(R.layout.main);
}
@Override
public boolean onDown(MotionEvent e) {
viewA.setText("Down Stroke");
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
viewA.setText("tap");
return true;
}
}