0

I have a view, I want to place it at (x, y) position via WindowManager.LayoutParams.

My code is:

mHeadLayoutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                PixelFormat.TRANSLUCENT);
        mHeadLayoutParams.gravity = Gravity.TOP | Gravity.END;
        mHeadLayoutParams.x = -20;
        mHeadLayoutParams.y = _screenSize.y * 15 / 100;

But mHeadLayoutParams.x = -20 does not same on others device screen. How can I calculate this value to my view placed on same position on multi device screen?

my image

Sorry for my bad english.

Ngoc Trung
  • 35
  • 7

2 Answers2

1

It seem right when use : mHeadLayoutParams.x = (int)-(20 * density + 0.5f)

Ngoc Trung
  • 35
  • 7
1

Use Screen ratio and density in mHeadLayoutParams.x & mHeadLayoutParams.y . It will automatically support multi screen.