Android widget xy

Can I get the coordinates of the XY widget on the main screen? I need to display a popup relative to the position of the widget, so I need to get the X and Y coordinates.

thank

+5
source share
2 answers

This is part of the intent used when you click on the widget. Just call getSourceBounds () on the Intent used to trigger your activity.

+11
source

This encoding also helped me find out the coordinates of the XY widget on the main screen.

   ImageView iv; 
   iv.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View view) {
                    Toast.makeText(bb.this, "text", Toast.LENGTH_LONG).show();
                    values    = new int[2]; 
                    view.getLocationOnScreen(values);
                    Log.d("X & Y",values[0]+" "+values[1]);
                }
            });
+1
source

All Articles