如何在自定义坐标上定位自定义对话框?

时间:2013-05-07 12:12:03

标签: android canvas view dialog coordinates

我是Android开发的菜鸟,我正在试图弄清楚如何在视图中的特定坐标处显示NewQuickAction3D弹出对话框。我正在将弹出窗口与this教程集成。基本上,我想使用弹出对话框来显示用户触摸的数据,而不是使用“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 个答案:

答案 0 :(得分:12)

覆盖视图的onTouch()

AlertDialog对话框;

@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();
  }

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