[英]OnTouchListener is not responding
I am creating a little popup like the facebook's chathead. 我正在创建一个类似Facebook聊天头的弹出窗口。
The bubble fires up and appears but the ontouchlistener
is not responding on it 气泡触发并出现,但
ontouchlistener
对此没有响应
the ontouch
events does what It is supposed to do when I tested it but when I integrated it, it's not firing 当我测试
ontouch
事件时,它应该执行该操作,但是当我对其进行集成时,它不会触发
Below is the code I used to create the layout of the bubble and ontouchlistener
以下是我用来创建气泡和
ontouchlistener
布局的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();
}
}
Hi You have added Framelayout first then get its child Using LayoutInflator. 您好,您首先添加了Framelayout,然后使用LayoutInflator获取其子级。 You have to first initialize all view and listeners then added it to window manager.
您必须首先初始化所有视图和侦听器,然后将其添加到窗口管理器。
Check This Link : http://www.piwai.info/chatheads-basics/ 检查此链接: http : //www.piwai.info/chatheads-basics/
That's it.. 而已..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.