双击活动扩展视图

时间:2018-02-08 21:56:18

标签: java android android-studio

我正在开发用于绘画的Android应用程序,我希望当我双击时,视图中会出现一个位图。在这里我做了一些调试,但我不知道为什么它不起作用。

实际上这个类实现了另一个包含Touchevent和motion事件的TouchEventView类。

我试过在另一个类中也实现了双击,但它不能正常工作

public class PlotActivity extends AppCompatActivity implements 
GestureDetector.OnDoubleTapListener,GestureDetector.OnGestureListener{

private TouchEventView tev;
private TextView message;
private GestureDetectorCompat gestureDetector;
public static final String DEBUGTAG="JWP";
Button enreg;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_plot);
    tev = (TouchEventView) findViewById(R.id.canva);
    this.gestureDetector = new GestureDetectorCompat(this, this);
    gestureDetector.setOnDoubleTapListener(this);

}

public void clearCanvas(View v){
    tev.clearCanvas();
}
public void enregInfo(View v){
    tev.savetofile();
}

@Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
    Log.i(DEBUGTAG, "onLongPress: " );
    return true;
}

@Override
public boolean onTouchEvent(MotionEvent event){
    this.gestureDetector.onTouchEvent(event);
    return super.onTouchEvent(event);
}

@Override
public boolean onDoubleTap(MotionEvent motionEvent) {
    Log.i(DEBUGTAG, "onLongPress: " );
    return true;
}

@Override
public boolean onDoubleTapEvent(MotionEvent motionEvent) {
    Log.i(DEBUGTAG, "onLongPress: " );
    return true;
}

@Override
public boolean onDown(MotionEvent motionEvent) {
    return true;
}

@Override
public void onShowPress(MotionEvent motionEvent) {

}

@Override
public boolean onSingleTapUp(MotionEvent motionEvent) {
    return true;
}

@Override
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
    return true;
}

@Override
public void onLongPress(MotionEvent motionEvent) {

}

@Override
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
    return true;
}

}

0 个答案:

没有答案