我目前正在使用此实现
LinearLayout touchLayout = new LinearLayout(this);
// set layout
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
touchLayout.setLayoutParams(lp);
// set on touch listener
touchLayout.setOnTouchListener(this);
touchLayout.setFocusableInTouchMode(false);
touchLayout.setFocusable(false);
touchLayout.setClickable(false);
// fetch window manager object
WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
// set layout parameter of window manager
WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, // width is equal to full screen
WindowManager.LayoutParams.MATCH_PARENT, // height is equal to full screen
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT , //
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, // this window won't ever get key input focus
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.LEFT | Gravity.TOP;
mWindowManager.addView(touchLayout, mParams);
唯一的问题是用户无法与我放置的LinearLayout后面的任何内容进行交互。
答案 0 :(得分:0)
只需在活动窗口或XML文件的根元素上设置touchlistener,然后根据需要决定如何/在何处分配触摸