本文介绍了窗口管理器,使用动画(这可能吗?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以使用​​充气动画窗口管理视图(在android的项目)?我不能做到这一点,即使使用网站的例子!我用了很多例子,但没有工作!

 公共BannerLayout(活动活动,最终的上下文语境){
    超(上下文);

    this.context =背景;

    最后WindowManager.LayoutParams PARAMS =新WindowManager.LayoutParams(
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);

    WM =(窗口管理器)context.getSystemService(Context.WINDOW_SERVICE);

    LayoutInflater充气=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.popupLayout =(RelativeLayout的)inflater.inflate(R.layout.popup_activity,NULL);
    this.popupLayout.setVisibility(GONE);
    this.setActive(假);

    wm.addView(this.popupLayout,则params);

    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}


私人无效秀(){
    动画= AnimationUtils.loadAnimation(this.context,android.R.anim.fade_in);
    this.popupLayout.setAnimation(在);

    this.setActive(真正的);
    this.popupLayout.setVisibility(可见);
}
 

解决方案

我不知道有关你的任务的具体要求,但有两种方法提供动画窗口:

  1. 使用 WindowManager.LayoutParams.windowAnimations 这样的:

      params.windowAnimations = android.R.style.Animation_Translucent;
     

  2. 添加产生额外的容器观点,因为窗口管理器不是一个真正的的ViewGroup 等正常动画添加意见是不工作的。 这个问题已经被问已经,但它缺乏code。我会运用它通过以下方式:

     公共类BannerLayout扩展视图{
    
        私人最终语境mContext;
    
        私人最终的ViewGroup mPopupLayout;
    
        私人最终的ViewGroup mParentView;
    
        公共BannerLayout(活动活动,最终的上下文语境){
            超(上下文);
    
            mContext =背景;
    
            最后WindowManager.LayoutParams PARAMS =新WindowManager.LayoutParams(
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
                            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                    PixelFormat.TRANSLUCENT);
    
            最后的窗口管理mWinManager =(窗口管理器)context.getSystemService(Context.WINDOW_SERVICE);
    
            LayoutInflater充气=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mPopupLayout =(RelativeLayout的)inflater.inflate(R.layout.popup_activity,NULL);
            mPopupLayout.setVisibility(GONE);
    
            params.width = ActionBar.LayoutParams.WRAP_CONTENT;
            params.height = ActionBar.LayoutParams.WRAP_CONTENT;
    
            //默认变异
            // params.windowAnimations = android.R.style.Animation_Translucent;
    
            mParentView =新的FrameLayout(mContext);
    
            mWinManager.addView(mParentView,则params);
    
            mParentView.addView(mPopupLayout);
            mPopupLayout.setVisibility(GONE);
        }
    
        / **
         *显示视图
         * /
        公共无效展(){
            在= AnimationUtils.loadAnimation(this.mContext,android.R.anim.fade_in)最终动画;
    
            in.setDuration(2000);
    
            mPopupLayout.setVisibility(可见);
            mPopupLayout.startAnimation(在);
        }
    
        / **
         *隐藏查看
         * /
        公共无效隐藏(){
            mPopupLayout.setVisibility(GONE);
        }
    }
     

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);
}
解决方案

I'm not sure about exact requirements for Your task, but there's two ways to provide animation to window:

  1. Use WindowManager.LayoutParams.windowAnimations like the following:

    params.windowAnimations = android.R.style.Animation_Translucent;
    

  2. Add additonal 'container' view, because WindowManager is not a real ViewGroup 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:

    public class BannerLayout extends View {
    
        private final Context mContext;
    
        private final ViewGroup mPopupLayout;
    
        private final ViewGroup mParentView;
    
        public BannerLayout(Activity activity, final Context context) {
            super(context);
    
            mContext = 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);
    
            final WindowManager mWinManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mPopupLayout = (RelativeLayout) inflater.inflate(R.layout.popup_activity, null);
            mPopupLayout.setVisibility(GONE);
    
            params.width = ActionBar.LayoutParams.WRAP_CONTENT;
            params.height = ActionBar.LayoutParams.WRAP_CONTENT;
    
            // Default variant
            // params.windowAnimations = android.R.style.Animation_Translucent;
    
            mParentView = new FrameLayout(mContext);
    
            mWinManager.addView(mParentView, params);
    
            mParentView.addView(mPopupLayout);
            mPopupLayout.setVisibility(GONE);
        }
    
        /**
         * Shows view
         */
        public void show(){
            final Animation in = AnimationUtils.loadAnimation(this.mContext, android.R.anim.fade_in);
    
            in.setDuration(2000);
    
            mPopupLayout.setVisibility(VISIBLE);
            mPopupLayout.startAnimation(in);
        }
    
        /**
         * Hides view
         */
        public void hide() {
            mPopupLayout.setVisibility(GONE);
        }
    }
    

这篇关于窗口管理器,使用动画(这可能吗?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:49