2

I'm not sure if x and y parameters should be pixels of DensityIndependentPixels.

I've tried to get this information from Android's documentation but there's no answer: showAtLocation docs

After digging deeper I've only got more questions:

The WindowManager.LayoutParams docs contains more explaination about x and y: WindowManager.LayoutParams documantation yet still not the one that I'm looking for.

GianhTran
  • 3,443
  • 2
  • 22
  • 42
Marcin Wróblewski
  • 811
  • 1
  • 10
  • 25

1 Answers1

1

X/Y in layout params use pixels as their unit. You can take a look at this How to show PopupWindow at special location? for more information on how-to.

Extra: you can also convert this value with

float density = context.getResources().getDisplayMetrics().density;
float px = someDpValue * density;
float dp = somePxValue / density;

Extra 2: you can also get width/height of the screen

DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();    
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
ReDLaNN
  • 484
  • 4
  • 14