gpt4 book ai didi

java - OnTouchListener 没有响应

转载 作者:太空宇宙 更新时间:2023-11-04 12:59:07 25 4
gpt4 key购买 nike

我正在创建一个像 Facebook 聊天头一样的小弹出窗口。

气泡启动并出现,但 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 获取其子级。您必须首先初始化所有 View 和监听器,然后将其添加到窗口管理器。

检查此链接:http://www.piwai.info/chatheads-basics/

就是这样..

关于java - OnTouchListener 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35078306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com