当前位置: 首页 > wzjs >正文

商务网站主页设计公司哈尔滨关键词排名工具

商务网站主页设计公司,哈尔滨关键词排名工具,物流门户网站源码,安阳流调报告一,概述 本文参考android.view.ScaleGestureDetector,对双指旋转手势做了一层封装,采用了向量计算法简单实现,笔者在此分享下。 二,实例 如下,使用RotateGestureDetector即可委托,实现旋转手…

一,概述

本文参考android.view.ScaleGestureDetector,对双指旋转手势做了一层封装,采用了向量计算法简单实现,笔者在此分享下。

二,实例

如下,使用RotateGestureDetector即可委托,实现旋转手势的简单封装,在对应Callback获取到旋转值设置到View即可。

public class RectView extends FrameLayout {private static final String TAG = "RectView";private View mRotateView;private final ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {@Overridepublic boolean onScale(@NonNull ScaleGestureDetector detector) {Log.d(TAG, "onScale() called with: detector = [" + detector.getScaleFactor() + "]");mRotateView.setScaleX(detector.getScaleFactor());mRotateView.setScaleY(detector.getScaleFactor());return true;}@Overridepublic boolean onScaleBegin(@NonNull ScaleGestureDetector detector) {return super.onScaleBegin(detector);}@Overridepublic void onScaleEnd(@NonNull ScaleGestureDetector detector) {super.onScaleEnd(detector);}});private final RotateGestureDetector rotateGestureDetector = new RotateGestureDetector(new RotateGestureDetector.Listener() {@Overridepublic void onRotateStart(RotateGestureDetector detector) {}@Overridepublic void onRotating(RotateGestureDetector detector) {mRotateView.setRotation((float) detector.eulerAngle);}@Overridepublic void onRotateEnd(RotateGestureDetector detector) {}});public RectView(Context context) {super(context);mRotateView = new View(context);mRotateView.setBackgroundColor(Color.GRAY);this.addView(mRotateView, new FrameLayout.LayoutParams(100, 100, Gravity.CENTER));}public RectView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);}public RectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);}public RectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {super(context, attrs, defStyleAttr, defStyleRes);}//    @SuppressLint("ClickableViewAccessibility")
//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        rotateGestureDetector.onTouchEvent(event);
//        return true;
//    }@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {rotateGestureDetector.onTouchEvent(ev);scaleGestureDetector.onTouchEvent(ev);return true;}
}

三,实现

Rotate具体实现如下,仅供参考。

import android.view.MotionEvent;import androidx.annotation.NonNull;/*** @author :zhong.jw* @date :Created in 2023/2/23 13:39* 旋转手势相关:采用向量法计算角度*/
public final class RotateGestureDetector {private static final double DEFAULT_LIMIT_START = 3f;@NonNullprivate final Listener listener;/*** 是否旋转中*/public boolean isRotating = false;/*** 旋转轴点x*/public int focusX;/*** 旋转轴点y*/public int focusY;/*** 欧拉角,范围[-180~180]*/public double eulerAngle = 0;/*** 弧度*/public double radian = 0;/*** 开始旋转的初始向量x值*/public double x1 = 0;/*** 开始旋转的初始向量y值*/public double y1 = 0;/*** 开始旋转的初始向量斜率*/public double k1 = 0;public RotateGestureDetector(@NonNull Listener listener) {this.listener = listener;}public boolean onTouchEvent(MotionEvent event) {int action = event.getActionMasked();int pointCount = event.getPointerCount();if ((action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) && (pointCount == 2) && !isRotating) {double e1x = event.getX(0);double e2x = event.getX(1);double e1y = event.getY(0);double e2y = event.getY(1);focusX = (int) (e1x + e2x) / 2;focusY = (int) ((e1y + e2y) / 2);x1 = e2x - e1x;y1 = e2y - e1y;k1 = y1 / x1;return true;}if (action == MotionEvent.ACTION_MOVE && pointCount == 2) {double e1x = event.getX(0);double e2x = event.getX(1);double e1y = event.getY(0);double e2y = event.getY(1);double x2 = e2x - e1x;double y2 = e2y - e1y;//angle = arccos(ab/(|a||b|))radian = Math.acos((x1 * x2 + y1 * y2) / (Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2)) * Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2))));// y = k1*x2 > y2 来判断是否属于外角eulerAngle = (radian / Math.PI * 180) * (k1 * x2 > y2 ? -1 : 1);if (isRotating) {listener.onRotating(this);}if (Math.abs(eulerAngle) >= DEFAULT_LIMIT_START) {isRotating = true;listener.onRotateStart(this);}return true;}if ((action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) && isRotating) {isRotating = false;listener.onRotateEnd(this);}return true;}public interface Listener {/*** @param detector:旋转信息*/void onRotateStart(RotateGestureDetector detector);/*** @param detector:旋转信息*/void onRotating(RotateGestureDetector detector);/*** @param detector:旋转信息*/void onRotateEnd(RotateGestureDetector detector);}}

http://www.dtcms.com/wzjs/73447.html

相关文章:

  • 培训网页设计吗合肥网站seo公司
  • 网站添加音乐有哪些平台可以免费发广告
  • 网站建设人力资源人员配置大连百度网站排名优化
  • 网站维护和推广方案媒体公关
  • 网站系统维护中企业网站设计模板
  • 房地产网站怎么做免费网络推广网站
  • 临沂公司做网站线上推广公司
  • 不用开源程序怎么做网站网站自助建站系统
  • 企业网站建设需要提供什么内容长尾关键词搜索网站
  • 网站的开发流程有哪几个阶段seo推广优化培训
  • b2b电子商务网站有哪些特点搜索引擎优化seo的英文全称是
  • 可以做彩票广告的网站吗爱战网关键词
  • 威海网站建设上海百度整站优化服务
  • 无网站做cpa防疫测温健康码核验一体机
  • 生物医药网站建设收录排名好的发帖网站
  • 胶南网站建设百度推广的五大优势
  • 网络公司排名100名河南网站seo靠谱
  • 网站建设及运营互联网营销主要学什么
  • 网页设计与网站建设的概述英文seo外链
  • 网页设计与制作教程期末考试题电商seo引流
  • 网站建设目标和功能介绍友情链接的检查方法
  • 网站建设公司模板苏州百度代理公司
  • 介休门户网站2023年8月新冠
  • 中国专门做统计网站河南制作网站
  • 成都房地产最新政策信息流广告优化师培训
  • 深圳网络公司视频东莞seo优化
  • vr 做的网站文件关键词搜索工具
  • 电脑做网站主机空间潮州seo
  • 网站设计的实例自媒体平台注册官网
  • 学习java可以自己做网站吗南宁seo产品优化服务