Beispiel #1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    /** 此处可添加修改高度的,没有用到 */
    int action = event.getAction();

    switch (action) {
      case MotionEvent.ACTION_MOVE:
        break;
      case MotionEvent.ACTION_DOWN:
        break;
      case MotionEvent.ACTION_UP:
        float rawX = event.getRawX();
        float rawY = event.getRawY();
        float x = event.getX();
        float y = event.getY();
        System.out.println("X--" + x);
        System.out.println("y" + y);
        int[] location = new int[2];
        cv_chart.getLocationOnScreen(location);
        float offsetY = y - location[1];
        float offsetX = x - 50;
        System.out.println("x--" + location[0]);
        System.out.println("y--" + location[1]);
        System.out.println("offsetX--" + offsetX);
        System.out.println("offsetY--" + offsetY);
        judgeHeight(offsetY);
        if (offsetX < 50 + ChartView.width / 4 / 2) {
          /** 修改第一列的数据 */
          x1 = judgeHeight(offsetY);
        } else if (offsetX < 50 + ChartView.width * 3 / 4 / 2) {
          /** 修改第二列的数据 */
          x2 = judgeHeight(offsetY);
        } else if (offsetX < 50 + ChartView.width * 5 / 4 / 2) {
          /** 修改第三列的数据 */
          x3 = judgeHeight(offsetY);
        } else if (offsetX < 50 + ChartView.width * 7 / 4 / 2) {
          /** 修改第四列的数据 */
          x4 = judgeHeight(offsetY);
        } else {
          /** 修改第五列的数据 */
          x5 = judgeHeight(offsetY);
        }
        cv_chart.invalidate();
        break;
    }
    return super.onTouchEvent(event);
  }