gpt4 book ai didi

android - 如何在特定坐标处定位自定义对话框?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:00:35 24 4
gpt4 key购买 nike

我是 android 开发的菜鸟,我想弄清楚如何在 View 中的特定坐标处显示 NewQuickAction3D 弹出对话框。我正在将弹出窗口与 this 集成教程。本质上,我想使用弹出对话框在用户触摸的地方显示数据,而不是使用“infoview”在 Canvas 上绘画目前,弹出窗口显示在我锚定它的 View 的顶部和中心。我怎样才能让它显示一个特定的坐标?非常感谢任何帮助。

我的代码

public void updateMsg(String t_info, float t_x, float t_y, int t_c){
infoView.updateInfo(t_info, t_x, t_y, t_c); //Infoview paints to on a specific coordinate
quickAction.show(infoView); //How do I use the t_x & t_y coordinates here instead of just anchoring infoview

编辑

public void updateMsg(String t_info, float t_x, float t_y, int t_c){
infoView.updateInfo(t_info, t_x, t_y, t_c);
WindowManager.LayoutParams wmlp = quickAction.getWindow().getAttributes(); //Error here getting window attributes
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 100; //x position
wmlp.y = 100; //y position
quickAction.show(infoView);
}

最佳答案

覆盖 View 的 onTouch()

AlertDialog dialog;

@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:

showDialog(); // display dialog
break;
case MotionEvent.ACTION_MOVE:
if(dialog!=null)
dialog.dismiss();
// do something
break;
case MotionEvent.ACTION_UP:
// do somethig
break;
}
return true;
}
public void showDialog()
{

AlertDialog.Builder builder = new AlertDialog.Builder(FingerPaintActivity.this);
dialog = builder.create();
dialog.setTitle("my dialog");
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 100; //x position
wmlp.y = 100; //y position
dialog.show();
}

即使绘制用户触摸屏幕,也会显示对话框。所以关闭移动中的对话框。

关于android - 如何在特定坐标处定位自定义对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16418740/

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