旋转方框功能实现图解


代码实现 1.采用矩阵映射,得到旋转后的功能按钮的新坐标(旋转按钮,删除按钮,缩放按钮)
  //检测点击是否在范围      getTouchRect(rotateRect).contains(x1, y1);       //得到旋转后按钮点击事件框      public RectF getTouchRect(RectF rect){//          System.out.println("处理触摸事件。。。。");            if(matrix==null){                  return rect;            }          matrix.mapRect(tempRect,rect);          return tempRect;      }

2.计算角度
判断三点是顺时针还是逆时针方向 资料:http://blog.sina.com.cn/s/blog_631f9e4b0100g874.html    已知三点求 三点之间夹角角度 资料:http://blog.csdn.net/lilin8905/article/details/69373069
public static double calcAngle(Point cen, Point first, Point second)       {           final double M_PI = 3.1415926535897  ;                  double ma_x = first.x - cen.x;           double ma_y = first.y - cen.y;           double mb_x = second.x - cen.x;           double mb_y = second.y - cen.y;           double v1 = (ma_x * mb_x) + (ma_y * mb_y);           double ma_val = Math.sqrt(ma_x * ma_x + ma_y * ma_y);           double mb_val = Math.sqrt(mb_x * mb_x + mb_y * mb_y);           double cosM = v1 / (ma_val * mb_val);           double angleAMB = Math.acos(cosM) * 180 / M_PI;                                   int v=(cen.x-first.x)*(second.y-cen.y)-(cen.y-first.y)*(second.x-cen.x);          if(v>0){//          System.out.println("逆时针");            return -angleAMB;          }else if(v<0){//          System.out.println("顺时针");          }else{//          System.out.println("不变");          }          return angleAMB;       }

3.绘制图形

 @Override

 public void onDraw(Canvas canvas) {                        canvas.save();            canvas.rotate(degree,rect.left+(rect.right-rect.left)/2,rect.top+(rect.bottom-rect.top)/2); //以矩形中心点旋转图形            canvas.drawRect(rect, paint);            if(isEdit){                               canvas.drawBitmap(deleteIcon, deleteRect.left, deleteRect.top, paint);                  canvas.drawBitmap(resizeIcon, resizeRect.left, resizeRect.top, paint);                  canvas.drawBitmap(rotateIcon, rotateRect.left, rotateRect.top, paint);            }            canvas.restore();   }


更多相关文章

  1. Android中MAT、GIMP查看内存占用
  2. cocos2d-x之优化图形性能-IOS/Android
  3. android 显示进度的按钮
  4. Android(安卓)开始支持Vulkan图形编程接口标准
  5. Android图形---OpenGL
  6. Android:自定义标题栏
  7. Android图形绘制基础(二)
  8. 类 QQ登入界面的 布局,防登入按钮被覆盖
  9. Android(安卓)AlertDialog和ProgressDialog

随机推荐

  1. Android入门教程(四)之------Android工程
  2. Android(安卓)小项目之--SQLite 使用法门
  3. Android(安卓)9 (P)系统启动之SystemServ
  4. Android面试系列文章2018之Android部分事
  5. libacc : Android(安卓)2.0 內建的輕量級
  6. Android(安卓)轻松实现语音识别的完整代
  7. Android开发工程师 iOS开发工程师正在招
  8. android体系结构
  9. 浅谈android的selector,背景选择器
  10. 浅谈android的selector背景选择器