Girish Garg
Girish Garg

Reputation: 58

How to place views on top of other views without using WindowManger?

Context:

My android library requires to dynamically place views on on top of other target views. Currently I am using WindowManager for this purpose. I have the viewId of the target views and get the location coordinates of the views. Now I simply use windowManager.addView(). Issue faced here is that WindowManager requires SYSTEM_ALERT_WINDOW permission which we want to avoid.

I have also tried getWindow().getDecorView().findViewById(android.R.id.content).addView(imageView), so that I donot have to use WindowManger but it is causing alignment issues for different phones. Any help on how we could avoid using WindowManager and still fulfill our purpose at the same time?

Alternative solution: I recently read this stackoverflow answer which said that permission won't be asked if installed from playstore. So I launched my app on playstore but it still asks for permission during runtime. I have also filled this form.

Edit:

  1. Using ViewOverlay as suggested by Mike. Issue is that drawables can only be added upto the region where associated View extends. Image
  2. Using getWindow().getDecorView().findViewById(android.R.id.content).addView(imageView) Issue is that we get different alignment for different screens. Screen 1 Screen 2
  3. Using WindowManager. Require SYSTEM_ALERT_WINDOW permission which we want to avoid.

Upvotes: 0

Views: 291

Answers (0)

Related Questions