내 앱에서 팝업 대화 상자를 만들고 싶습니다. 대화 상자는 활동으로 가장 잘 수행됩니다. 그런 다음 내 매니페스트에서 "Theme.Dialog"를 사용하여 활동을 대화 상자로 작동시킵니다. 그건 잘 작동합니다.Android : 대화 상자로 활동 위치
내가 원하는 곳에서 팝업을 배치하는 것이 효과가없는 것 같습니다.
여기 팝업 메뉴는 원형 메뉴 인 원형 버튼 위에 배치됩니다. "도넛"주위에 여섯 개의 아이콘이 배열 된 단지 상대 레이아웃
내가 원하는 것은 몇 개의 원형 버튼 중 하나를 통해 화면에 팝업이 표시되도록하려는 것입니다. 어떤 버튼이 눌러 졌는지에 따라, 눌린 뷰 (버튼)의 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 위치를 두지 않습니다.
0,0에 배치하면 화면의 중앙에 있고 X/Y 위치를 음수로 설정하면 왼쪽으로 강제로 이동합니다. 수학이 문서를 기반으로 기대 한 바가 아니 었습니다.
이 대화 상자 창을 제대로 배치하기 위해 내가해야 할 일에 대해 누구나 알고 있습니까? 일반적인 예는 1280x800 화면 태블릿의 (400, 470)에있는 버튼입니다.
예, 사용자 정의보기 클래스가 작동 할 수 있지만 활동을 대화 상자로 사용해야합니다. – Martin