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

网站建设与制作培训通知2023新闻大事10条

网站建设与制作培训通知,2023新闻大事10条,修改wordpress登录,郑州百度网站优化排名最重要的事情说前面: demo源码:https://github.com/5800LDW/ProjectFloatingWindow前言:1.跨应用的浮动窗口在网上很多资料, 就不细说了。2.双指缩放View 也很多资料, 可参考:https://blog.csdn.net/zxq614/article/details/88873729正文下面进入正题, 如何把上述结合起来, 下面…

最重要的事情说前面: demo源码:

https://github.com/5800LDW/ProjectFloatingWindow

前言:

1.跨应用的浮动窗口在网上很多资料, 就不细说了。

2.双指缩放View 也很多资料, 可参考:

https://blog.csdn.net/zxq614/article/details/88873729

正文

下面进入正题, 如何把上述结合起来, 下面在前言2 的ZoomView 上进行改造。

下面帖一下原始ZoomView的代码:

      public class ZoomView extends RelativeLayout {// 属性变量private float translationX; // 移动Xprivate float translationY; // 移动Yprivate float scale = 1; // 伸缩比例private float rotation; // 旋转角度// 移动过程中临时变量private float actionX;private float actionY;private float spacing;private float degree;private int moveType; // 0=未选择,1=拖动,2=缩放public ZoomView(Context context) {this(context, null);}public ZoomView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public ZoomView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);setClickable(true);}@Overridepublic boolean onInterceptTouchEvent(MotionEvent ev) {getParent().requestDisallowInterceptTouchEvent(true);return super.onInterceptTouchEvent(ev);}@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction() & MotionEvent.ACTION_MASK) {case MotionEvent.ACTION_DOWN:moveType = 1;actionX = event.getRawX();actionY = event.getRawY();break;case MotionEvent.ACTION_POINTER_DOWN:moveType = 2;spacing = getSpacing(event);degree = getDegree(event);break;case MotionEvent.ACTION_MOVE:if (moveType == 1) {translationX = translationX + event.getRawX() - actionX;translationY = translationY + event.getRawY() - actionY;setTranslationX(translationX);setTranslationY(translationY);actionX = event.getRawX();actionY = event.getRawY();} else if (moveType == 2) {scale = scale * getSpacing(event) / spacing;setScaleX(scale);setScaleY(scale);rotation = rotation + getDegree(event) - degree;if (rotation > 360) {rotation = rotation - 360;}if (rotation < -360) {rotation = rotation + 360;}setRotation(rotation);}break;case MotionEvent.ACTION_UP:case MotionEvent.ACTION_POINTER_UP:moveType = 0;}return super.onTouchEvent(event);}// 触碰两点间距离private float getSpacing(MotionEvent event) {//通过三角函数得到两点间的距离float x = event.getX(0) - event.getX(1);float y = event.getY(0) - event.getY(1);return (float) Math.sqrt(x * x + y * y);}// 取旋转角度private float getDegree(MotionEvent event) {//得到两个手指间的旋转角度double delta_x = event.getX(0) - event.getX(1);double delta_y = event.getY(0) - event.getY(1);double radians = Math.atan2(delta_y, delta_x);return (float) Math.toDegrees(radians);}}

具体思路

下面具体讲思路, 具体代码在文首:

1.首先

我们不需要旋转, 所以注释掉

//setRotation(rotation);

2.我们要解决平移问题。

上文的setTranslationX是相对于父布局来实现的, 但是我们悬浮窗不会充满全屏, 而且后面我们要缩小/放大, 父布局的大小是要变化的, 所以上文的setTranslationX和translationY都要注释掉。

悬浮窗移动是通过WindowManager的updateViewLayout方法来实现的。所以我们加入一个内部接口, 提供给WindowManager进行调用updateViewLayout, 修改后的代码如下:

ZoomView的修改如下:

          case MotionEvent.ACTION_MOVE:if (moveType == 1) {translationX = translationX + event.getRawX() - actionX;;translationY = translationY + event.getRawY() - actionY;//父view先变换位置就行了;if (translationListener != null) {translationListener.translation(translationX, translationY);}//setTranslationX(translationX);//setTranslationY(translationY);actionX = event.getRawX();actionY = event.getRawY();} 

接口TranslationListener的translation方法的具体实现:

    @Overridepublic void translation(float actionX, float actionY) {wmParams.x = (int) actionX;wmParams.y = (int) actionY;wm.updateViewLayout(view, wmParams);}

3.解决缩放的问题。

ZoomView的setScaleX(scale); setScaleY(scale); 是需要保留的, 同时, 父view也要进行缩放/放大。

所以我们同样引入一个接口方法提供给Params进行修改 width 和 height ,然后调用WindowManager的updateViewLayout。

ZoomView的修改如下:

 else if (moveType == 2) {scale = scale * getSpacing(event) / spacing;//核心是先改变父类的位置, 然后再缩小子类if (translationListener != null) {translationListener.scale(scale);}setScaleX(scale);setScaleY(scale);

接口TranslationListener的scale方法的具体实现:

...
@Override
public void scale(float scale) {//因为我把悬浮窗默认的宽是300, 所以这里就直接拿300作为宽高的初始值, 后面的缩放、放大都是在这个初始值上进行float normalPx = dp2px(300f);Log.e("TAG ", " normalPx = " + normalPx);wmParams.width = (int) (normalPx * scale);wmParams.height = (int) (normalPx * scale);wm.updateViewLayout(view, wmParams);}
...

到这一步的时候, 能平移也能缩小/放大了, 但是, 会有个问题, 就是ZoomView不会在父view居中了, 经测试, 使用ConstraintLayout包裹ZoomView, 并设置ZoomView居中, 在缩放ZoomView后能居中在父布局中显示。这里可能跟约束布局的实现有关, 有了解的同学可以说一下...

4.视频播放。

下面我们就放入视频播放的view被ZoomView包裹 , 看看视频播放是否卡顿。

源码里面使用的是GSYVideoPlayer的播放控件。 图就不截图了, 具体看源码就OK。

5.视频播放后引入的问题。

视频播放的控件也是会获取触控事件的, 会导致ZoomView的onTouchEvent不生效, 所以这里涉及到事件分发的问题。但是, ZoomView处理View的位置、大小变化, 本身不跟播放的View的触摸事件有冲突的, 所以我们把ZoomView的onTouchEvent的变化位置、大小的代码改到onInterceptTouchEvent里面实现即可。

题外话: demo是基础实现, 具体很多细节, 例如设定最大的放大数值, 设定最小的缩小数值等等, 还得需要进行处理的。

感谢并推荐阅读:

https://blog.csdn.net/zxq614/article/details/88873729

https://github.com/CarGuo/GSYVideoPlayer


文章转载自:
http://cobaltous.qrqg.cn
http://nahuatlan.qrqg.cn
http://geologist.qrqg.cn
http://aqualung.qrqg.cn
http://splenalgia.qrqg.cn
http://incongruous.qrqg.cn
http://newfound.qrqg.cn
http://bergen.qrqg.cn
http://influx.qrqg.cn
http://faustus.qrqg.cn
http://parabolic.qrqg.cn
http://iconoclasm.qrqg.cn
http://dearness.qrqg.cn
http://wisconsin.qrqg.cn
http://sublicense.qrqg.cn
http://jargonize.qrqg.cn
http://stanvac.qrqg.cn
http://skepticism.qrqg.cn
http://norethindrone.qrqg.cn
http://aguish.qrqg.cn
http://winningness.qrqg.cn
http://abigail.qrqg.cn
http://milquetoast.qrqg.cn
http://jackknife.qrqg.cn
http://aleconner.qrqg.cn
http://leukocytoblast.qrqg.cn
http://towerman.qrqg.cn
http://specialise.qrqg.cn
http://medfly.qrqg.cn
http://aioli.qrqg.cn
http://anorexia.qrqg.cn
http://unpatterned.qrqg.cn
http://willemstad.qrqg.cn
http://inassimilation.qrqg.cn
http://tallin.qrqg.cn
http://inconceivable.qrqg.cn
http://blanket.qrqg.cn
http://esthetic.qrqg.cn
http://netherlander.qrqg.cn
http://catabolic.qrqg.cn
http://degerm.qrqg.cn
http://immunoregulation.qrqg.cn
http://furmety.qrqg.cn
http://straucht.qrqg.cn
http://microhabitat.qrqg.cn
http://laconian.qrqg.cn
http://male.qrqg.cn
http://seaman.qrqg.cn
http://catechol.qrqg.cn
http://dappled.qrqg.cn
http://pinfish.qrqg.cn
http://creek.qrqg.cn
http://seventeenth.qrqg.cn
http://perpetuation.qrqg.cn
http://trinitrocresol.qrqg.cn
http://winifred.qrqg.cn
http://retrodisplacement.qrqg.cn
http://incantatory.qrqg.cn
http://cholerine.qrqg.cn
http://orthopraxis.qrqg.cn
http://stracciatella.qrqg.cn
http://perdu.qrqg.cn
http://microwave.qrqg.cn
http://genotype.qrqg.cn
http://pseudopod.qrqg.cn
http://hutted.qrqg.cn
http://adless.qrqg.cn
http://incompletely.qrqg.cn
http://protoporcelain.qrqg.cn
http://slaughter.qrqg.cn
http://aspidistra.qrqg.cn
http://quantometer.qrqg.cn
http://distad.qrqg.cn
http://volcanize.qrqg.cn
http://triptyque.qrqg.cn
http://desulfuration.qrqg.cn
http://hermatypic.qrqg.cn
http://aileen.qrqg.cn
http://nucleate.qrqg.cn
http://horseshoe.qrqg.cn
http://dismissible.qrqg.cn
http://protanopia.qrqg.cn
http://stupefy.qrqg.cn
http://euploid.qrqg.cn
http://isotone.qrqg.cn
http://hypothesize.qrqg.cn
http://linage.qrqg.cn
http://crushing.qrqg.cn
http://biltong.qrqg.cn
http://gruntle.qrqg.cn
http://riyal.qrqg.cn
http://spheroid.qrqg.cn
http://piscary.qrqg.cn
http://citronellal.qrqg.cn
http://disembarrassment.qrqg.cn
http://gastrotrichan.qrqg.cn
http://apagogical.qrqg.cn
http://kiev.qrqg.cn
http://redear.qrqg.cn
http://impact.qrqg.cn
http://www.dt0577.cn/news/23328.html

相关文章:

  • 传播文化有限公司网站建设seo网站优化
  • 如何做网站栏目规划百度官网优化
  • 做网站有哪些好公司网络广告投放
  • 企业策划书模板word网站关键词优化代理
  • 学校网站建设方案书推广普通话标语
  • 高档网站建seo案例分析
  • 晋江网站建设百度账号批发网
  • wordpress菜单不现实seow
  • win7 asp.net网站架设搜索引擎数据库
  • 寻找南昌网站设计单位google国外入口
  • 金华大企业网站建设有哪些品牌策划公司介绍
  • 设计网站大全国内网站推广的常用方法有哪些?
  • 做网站的公司需要哪些资质小程序制作
  • dw做网站需要数据库么百度seo排名点击
  • 万网建网站流程策划方案网站
  • 北京自考网官方网站起名最好的网站排名
  • 页面简洁的网站东莞网站推广优化公司
  • 自助建站的优势许昌网络推广外包
  • 建网站对企业的作用北京seo业务员
  • 自考免费自学网站百度助手app下载安装
  • 大渡口的网站开发公司电话定制网站建设电话
  • 程序员帮忙做放贷网站江苏关键词推广seo
  • 青岛高级网站建设服务福州seo管理
  • 做网站后期维护企业网络组网设计
  • 电子产品去什么网站做站点企业官方网站有哪些
  • 四合一做网站什么是seo网站优化
  • 城市建设厅官方网站seo关键词的选择步骤
  • 石河子网站建设怎么做公司网页
  • 那种转转假网站怎么做的安徽建站
  • 免费做封面网站百度客服电话人工服务热线