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);
}
4

1 回答 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();
      }

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

于 2013-05-07T12:35:02.120 回答