我用WindowManager绘制了一个覆盖图。它的宽度和高度是
WindowManager.LayoutParams.MATCH_PARENT
背景透明。
我的视图必须匹配父对象和句柄圆触摸侦听器,并将其余的触摸传递到下面的屏幕
我有两个小的
circle in left and right corner
int LAYOUT_FLAG = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? WindowManager.
LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE;
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,//changed it to full
WindowManager.LayoutParams.MATCH_PARENT,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
///| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, this flag can make it in touchable.
///WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
PixelFormat.TRANSLUCENT);
mFloatingView = LayoutInflater.from(this).inflate(R.layout.item_circle_dragging, null);
mFloatingView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
});
//Add the view to the window
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingView,params);
项目圈_拖动.xm
我
<?xml version="1.0" encoding="utf-8"?>
<customviewpracticing.CircleDraggingView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</customviewpracticing.CircleDraggingView>
环行图
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if(isPointInside(event.getRawX(),event.getRawY()))
isAllowedToDrag = true;
Log.d(TAG, "ACTION_DOWN:getRawX= " + event.getRawX() + " getRawY= " + event.getRawY() + " getX= "
+ event.getX() + " getY= " + event.getY());
break;
///return true;
case MotionEvent.ACTION_MOVE:
Log.d(TAG, "ACTION_MOVE:getRawX= " + event.getRawX() + " getRawY= " + event.getRawY() + " getX= "
+ event.getX() + " getY= " + event.getY());
if(isAllowedToDrag){
center_circle_X = event.getRawX() ;
center_circle_Y = event.getRawY();
}/*this.animate().x(event.getRawX()).y(event.getRawY())
.setDuration(50).start();*/
break;
case MotionEvent.ACTION_UP:
if(isAllowedToDrag)
isAllowedToDrag = false;
break;
default:
return true;//I changed it
}
// Force a view to draw again
///postInvalidate();
invalidate();
return true;
}
也试过了
onTouchEvent
属于
CircleDraggingView
mFloatingView视图
(根视图)。