如何将自定义对话框定位到特定坐标?

8
我是一个Android开发的新手,正在尝试找出如何在视图中的特定坐标显示NewQuickAction3D弹出对话框。我正在将弹出与这个教程链接集成。本质上,我想使用弹出对话框来显示用户触摸的数据,而不是在画布上绘制“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); //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);
}
1个回答

15

重写您的视图的 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();
      }

即使用户触摸屏幕,对话框也会显示出来。因此,在移动中解散对话框。


谢谢回复。我对你的答案有些困惑。NewQuickAction是一个自定义对话框,所以它不允许我获取窗口属性。你有什么想法吗? - B. Money
将您的自定义视图作为活动类的内部类。 - Raghunandan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接