在Android上发射浮动小窗口/重叠 [英] Floating widget / Overlay on Android launcher

查看:175
本文介绍了在Android上发射浮动小窗口/重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有任何想法,这可怎么实现的?

Does anyone have any idea how this can be implemented?

一些例子:

  • https://play.google.com/store/apps/details?id=gpc.myweb.hinet.net.PopupWeb
  • https://play.google.com/store/apps/details?id=gpc.myweb.hinet.net.PopupVideo
  • https://play.google.com/store/apps/details?id=com.milone.floatwidget

你知道吗?谢谢你。

推荐答案

这是用在上面覆盖完成现有的活动不管。你可以找到在这里找到我的 github上源头上展示的概念的证明,这是对Android的<一个href="http://android.stackexchange.com/questions/25090/cant-scroll-using-hands-are-there-other-options">stackexchange.com问题在其中的人谁患了残疾,无法轻扫屏幕滚动并一直在寻找一种方式来方便地做到这一点,我在其中拼凑了code,以显示页面上/下页以最小的运动,只需轻敲上的文字(真的,它的一个按钮),它覆盖在一个活动上。但由于机器人和安全工作方式,滚动事件不能被注入到当前运行的活动

That is done using an overlay on top the existing activity regardless. You can find the source found here on my github to demonstrate the proof of concept that was on android's stackexchange.com question in which someone who suffered from a disability and could not swipe the screen to scroll and was looking for a way to do this conveniently, in which I cobbled together the code to show 'Page Up/Page Down' with minimum movement, just by tapping on the text (really, its a button) which overlaid on top of a activity. But due to the way Android and security worked, the scrolling event could not be injected into the currently running activity.

它的工作方式是这样的,从的onCreate 的活动有这种

The way it works is this, from the onCreate activity there's this

WindowManager.LayoutParams layOutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);

这是必要的标志是 WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH

有责任确保触摸被处理,这意味着看出来,当触摸事件'打'的一个区域,并采取相应的行动。通过听在视图的 onTouch 的事件,那就是:

The onus is to ensure that the touch is being handled which means watching out when the touch event 'hits' on a area and to act accordingly. By "listening" in on the View's onTouch event, that is:

LayoutInflater layOutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View myView = layOutInflater.inflate(R.layout.myview, null);

myView.setOnTouchListener(new OnTouchListener(){
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      ....
    }
});

例如,假设在一个按钮 MyView的的布局,所以用一个按钮控件,

For example, imagine a button within that myview layout, so using a button widget,

Button myButton = (Button)myView.findViewById(R.id.myButton);
Rect outRectHit = new Rect();
myButton.getHitRect(outRectHit);

现在我们需要来确定触摸的边界的碰撞,这发生在 onTouch 处理器中:

Now we need to determine the 'collision' of the boundaries of the touch, which happens inside the onTouch handler:

float x = event.getX();
float y = event.getY();
if (x > outRectHit.left && x < outRectHit.right &&
    y > outRectHit.top && y < outRectHit.bottom){
     ... Handle this accordingly
}

此简要介绍了如何做这样的事情,在最上层的任何活动的叠加。

This brief summary explains how to do such a thing as an overlay on-top of any activity.

只是为了确保,即code被调试,并在任何形状或形式与表现出任何活动不会干扰。例如,你有什么做什么,如果该活动实际上是OpenGL的游戏情况,?

Just to make sure, that the code gets debugged and does not interfere in any shape or form with any activity shown. For example, what happens if the activity is in fact a OpenGL game, what do you do?

这是说明什么需要警惕的。

That is to illustrate what needs to be watched out for.

这篇关于在Android上发射浮动小窗口/重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆