我想在我的应用程序中有一个弹出对话框。该对话最好作为一项活动完成。然后我使用我的清单中的“Theme.Dialog”使活动表现为对话框。这工作正常。Android:作为对话框的活动位置
似乎有什么不工作的定位,我想它的弹出窗口。
这里是弹出的模板,这应该在圆形 按钮为中心的圆形菜单。只是在“甜甜圈”周围布置了六个图标的相对布局
我想要做的是在屏幕上通过几个圆形按钮之一显示弹出窗口。根据按下哪个按钮,我收集按下的View(按钮)的X/Y位置,并通过绑定将其发送到活动。然后,我想要使用按下按钮的位置和弹出窗口的大小来定位对话框,以便将它居中放置在按钮上方。
public class WirelessDialog extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.donut_dialogue);
// get the layout of the dialog
RelativeLayout rl = (RelativeLayout)findViewById(R.id.donut_layout);
// get base image all other icons reside on and compute its haLf-width/height
ImageView iv = (ImageView)findViewById(R.id.donut);
int half_width = iv.getWidth()/2 ;
int half_height = iv.getHeight()/2;
Bundle extras = getIntent().getExtras();
if (extras != null) {
int startX = extras.getInt("X");
int startY = extras.getInt("Y");
int endX = extras.getInt("XE");
int endY = extras.getInt("YE");
WindowManager.LayoutParams winParms = getWindow().getAttributes() ;
int x = winParms.x;
int y = winParms.y;
Log.d("DIALOG", "Original x/y: " + x + " " + y);
//int width = winParms.width;
//int height = winParms.height;
int xc = startX + (endX - startX + 1)/2;
int yc = startY + (endY - startY + 1)/2;
// new location of the dialog should be 1/2 the width and height of the donut subtracted
// from the center of the button that was pressed.
winParms.x = (xc - half_width);
winParms.y = (yc - half_height);
Log.d("DIALOG", "New x/y: " + winParms.x + " " + winParms.y);
getWindow().setAttributes(winParms);
}
}
设置布局参数只强制对话框到最右边。最初,这是 x/y位置返回为零,但任何非零数字甚至不会将其放置在位置指示的位置。
将其放置在0,0是屏幕的中心,并且设置X/Y位置为负力它到uppper左侧。数学不是我所期望的基于文档
任何人都有一个想法,我应该怎么做才能正确放置此对话窗口? 一个典型的例子是在1280x800屏幕平板电脑上的(400,470)按钮。
是的,自定义视图类可能会工作,但应该使用活动作为对话框。 – Martin 2013-05-03 16:10:16