有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何调用安卓的drawLine()

基于此应用程序:https://github.com/valerio-bozzolan/AcrylicPaint/blob/master/src/anupam/acrylic/EasyPaint.java

我想在菜单中添加另一项,即画一条线。我是安卓新手,所以请不要评判我:)以下是我的尝试:

public boolean onTouch(View v, MotionEvent event) {
             float downx = 0, downy = 0, upx = 0, upy = 0;
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
              downx = event.getX();
              downy = event.getY();
              break;
            case MotionEvent.ACTION_MOVE:
              break;
            case MotionEvent.ACTION_UP:
              upx = event.getX();
              upy = event.getY();
              mCanvas.drawLine(downx, downy, upx, upy, mPaint);  //<---
              invalidate();
              break;
            case MotionEvent.ACTION_CANCEL:
              break;
            default:
              break;
            }
            return true;
          }

我将这些行添加到onOptions ItemSelected中(第314行)

    @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {

            case R.id.LINE_ID:
//i need to call it here        
                return true;

谢谢


共 (0) 个答案