Android: location of activity as dialog -


i want have popup dialog in app. dialog best done activity. use "theme.dialog" in manifest cause activity behave dialog. works fine.

what doesn't seem work positioning popup want it.

here template of popup, circular menu should centered on circular button. relative layout 6 icons laid out around "donut" enter image description here

what want have popup displayed on screen on 1 of several circular buttons. depending on button pressed, collect x/y location of view (button) pressed , send on via bundle activity. want position dialog using location of pressed button , size of popup place it, centered, on button.

public class wirelessdialog extends activity {    @override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     //requestwindowfeature(window.feature_no_title);     setcontentview(r.layout.donut_dialogue);      // layout of dialog     relativelayout rl = (relativelayout)findviewbyid(r.id.donut_layout);      // base image other icons reside on , compute 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 dialog should 1/2 width , height of donut subtracted         // center of button pressed.          winparms.x = (xc - half_width);         winparms.y = (yc - half_height);         log.d("dialog", "new    x/y: " + winparms.x + " " + winparms.y);         getwindow().setattributes(winparms);     }  } 

setting layout parameters forces dialog far right. originally, it's x/y location comes zero, non-zero number doesn't place locations indicate.

placing @ 0,0 center of screen, , setting x/y locations negative forces uppper left. math isn't expected based on documentation

anyone have idea on should doing place dialog window? typical example button @ (400, 470) on 1280x800 screen tablet.

what in case:

create custom view class circular popup; instantiate view on activity intialization, if options ever same, of course; on button click listener, x,y, width , height, x , y positions be, buttonx + (buttonwidth / 2), buttony + (buttonheight / 2); add view , position on x , y positions.

to faster , "cheaper", view can instantiated @ creation of activity , invisble (android:visible="none" in view layout root element).

i think activity root layout must relativelayout or framelayout.

i think solution should work.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -