Purpose and General Description:
I'm working on displaying one of two layouts with varying sizes and animating their transition via a custom animation—successfully implemented without any issues. To manage this, I've set up a parent layout, a ConstraintLayout, to contain these two layouts. Using WindowManager.addView(), I present this ConstraintLayout to the user along with WindowManager.LayoutParams. These parameters ensure the ConstraintLayout accommodates the initially displayed layout among the two.
The ConstraintLayout serves as an overlay and should seamlessly overlay other applications. The displayed layout supports click events but isn't focusable. Moreover, the setup ensures that click events within this layout do not interfere with other parts of the screen.
The Actual Problem:
Upon attempting to resize the ConstraintLayout added by the WindowManager, an issue arises. The layout momentarily shifts to an unexpected position before swiftly returning to its intended place. This brief displacement significantly impacts the user experience.
What I've Tried:
(1) Attempted using a private flag within WindowManager.LayoutParams—PRIVATE_FLAG_NO_MOVE_ANIMATION = 0x00000040—without success.
(2) Tried removing the layout using WindowManager.removeView() and then re-adding it with addView() after updating the LayoutParams, but this approach also failed to resolve the issue. Despite exploring additional approaches, none seem to rectify this problem.
Code snippets
Resize code :
rootParams - LayoutParams . rootLayout - constraintLayout .
rootParams.width = (int) (300 * metrics.density);
rootParams.height = (int) (450 * metrics.density);
windowManager.updateViewLayout(rootLayout , rootParams);
Decliration of rootParams :
int LAYOUT_FLAG ;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY ;
}else{
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE ;
}
rootParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT , WindowManager.LayoutParams.WRAP_CONTENT , LAYOUT_FLAG , WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS , PixelFormat.TRANSLUCENT) ;
rootParams.gravity = Gravity.CENTER ;
I'd appreciate some help. Thanks to everyone who took the time to read this. :)
EXPECTATION :
the constraint layout should stay in its place , in the middle of the screen , while the transparent parent resized .