Java OnTouchListener没有响应
我正在创建一个类似facebook聊天头的小弹出窗口 气泡会激发并出现,但Java OnTouchListener没有响应,java,android,ontouchlistener,Java,Android,Ontouchlistener,我正在创建一个类似facebook聊天头的小弹出窗口 气泡会激发并出现,但ontouchlistener没有响应 当我测试它时,ontouch事件执行它应该执行的操作,但是当我集成它时,它不会触发 下面是我用来创建气泡布局和ontouchlistener public HeadLayer(Context context) { super(context); mContext = context; mFrameLayout = new FrameLayout(mConte
ontouchlistener
没有响应
当我测试它时,ontouch
事件执行它应该执行的操作,但是当我集成它时,它不会触发
下面是我用来创建气泡布局和ontouchlistener
public HeadLayer(Context context) {
super(context);
mContext = context;
mFrameLayout = new FrameLayout(mContext);
addToWindowManager();
}
private void addToWindowManager() {
final WindowManager.LayoutParams myParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
myParams.gravity = Gravity.LEFT;
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(mFrameLayout, myParams);
try{
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Here is the place where you can inject whatever layout you want.
View view = layoutInflater.inflate(R.layout.head, mFrameLayout);
//for moving the picture on touch and slide
headIcon = (ImageView)view.findViewById(R.id.head_icon);
headIcon.setOnTouchListener(new View.OnTouchListener() {
WindowManager.LayoutParams paramsT = myParams;
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY;
private long touchStartTime = 0;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
touchStartTime = System.currentTimeMillis();
initialX = myParams.x;
initialY = myParams.y;
initialTouchX = event.getRawX();
initialTouchY = event.getRawY();
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
myParams.x = initialX + (int) (event.getRawX() - initialTouchX);
myParams.y = initialY + (int) (event.getRawY() - initialTouchY);
mWindowManager.updateViewLayout(v, myParams);
break;
}
return false;
}
});
} catch (Exception e){
e.printStackTrace();
}
}
您好,您首先添加了Framelayout,然后使用LayoutInflator获取其子级。您必须首先初始化所有视图和侦听器,然后将其添加到窗口管理器中 检查此链接:
就是这样。您好,您首先添加了Framelayout,然后使用LayoutInflator获取其子级。您必须首先初始化所有视图和侦听器,然后将其添加到窗口管理器中 检查此链接:
就是这样。您是否尝试过在触摸时使用断点进行检查我认为
OnTouchListener()
中的变量在每次触摸事件时都会初始化。您是否尝试过更改static
变量,或移动到外部类?您是否尝试过在触摸时使用断点进行检查?我认为OnTouchListener()
中的变量在每次触摸事件时都会初始化。您是否尝试更改静态变量,或移动到外部类?