Is there any way to inflate a view with WindowManager using Animation (at android's project)? I just can't do it even using the examples in sites! I used many examples but none worked!
public BannerLayout(Activity activity, final Context context) {
super(context);
this.context = context;
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.popupLayout = (RelativeLayout) inflater.inflate(R.layout.popup_activity, null);
this.popupLayout.setVisibility(GONE);
this.setActive(false);
wm.addView(this.popupLayout, params);
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
private void show(){
Animation in = AnimationUtils.loadAnimation(this.context, android.R.anim.fade_in);
this.popupLayout.setAnimation(in);
this.setActive(true);
this.popupLayout.setVisibility(VISIBLE);
}
Yes it is indeed possible. As long as the view you want to animate is inside a container, by container I mean for instance a LinearLayout or any other layout will do. Conclusively the view to be animated should not be the root view of a window and so you should be able to animate the view
:)
Hope it helpsI'm not sure about exact requirements for Your task, but there's two ways to provide animation to window:
Use
WindowManager.LayoutParams.windowAnimations
like the following:Add additonal 'container' view, because
WindowManager
is not a realViewGroup
and so normal animation for adding views is not working with it. This question has been asked already, however it lacks the code. I would apply it the following way: