2013-05-07 74 views
4

我是android开发的noob,我想弄清楚如何在视图中的特定坐标处显示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); 
} 

回答

9

覆盖你的观点

AlertDialog对话框的onTouch();

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

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

+0

感谢您的回复。我的答案有些麻烦。 NewQuickAction是一个自定义对话框,所以它不会让我获得窗口属性。有什么想法吗? – 2013-05-07 12:49:27

+0

使您的自定义视图活动类的内部类 – Raghunandan 2013-05-07 12:51:52