2013-07-19 2 views
12

애니메이션 (안드로이드 프로젝트에서)을 사용하여 WindowManager에서 뷰를 부 풀릴 수있는 방법이 있습니까? 사이트의 예제를 사용해도 할 수 없습니다! 나는 많은 예제를 사용했지만 아무도 효과가 없었습니다!애니메이션이있는 WindowManager (가능합니까?)

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); 
} 

답변

28

나는 당신의 작업에 대한 정확한 요구 사항에 대해 잘 모르겠지만, 창에 애니메이션을 제공하는 두 가지 방법이있다 :

  1. 는 사용 WindowManager.LayoutParams.windowAnimations는 다음과 같이 :

    params.windowAnimations = android.R.style.Animation_Translucent; 
    
  2. WindowManager이 실제 ViewGroup이 아니므로 additonal 'container'보기를 추가하면보기를 추가하기위한 일반 애니메이션이 함께 작동하지 않으므로 추가하십시오. This question has been asked already하지만 코드가 없습니다.

    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); 
        } 
    } 
    
+0

sandrstar ... 완벽하게 작동했습니다! 그러나 ... 이러한 구성 요소로 애니메이션 번역을 사용할 수 있는지 궁금합니다. I가이 구성 요소가 화면 아래로 효과를 만들기 위해 ... – LeandroPortnoy

+0

개인 무효 쇼()가 필요합니다 { \t \t \t \t // 애니메이션 fadeIn = (애니메이션) AnimationUtils.loadAnimation (는 getContext(), android.R. anim.fade_in); \t \t // this.startAnimation(fadeIn); \t //this.bannerRelativeLayout.setVisibility(VISIBLE); \t \t \t \t this.setActive (true); mPopupLayout.setVisibility (VISIBLE); \t \t Final Animation in = new TranslateAnimation (0, 0, -1000, 0); in.setDuration (700); AnimationSet animation = 새 AnimationSet (거짓); animation.addAnimation (입력); \t mPopupLayout.startAnimation (animation); \t} – LeandroPortnoy

+0

죄송합니다. 나는 그것을 시도하고 잘 작동하는 것 같습니다. params.width = ViewGroup.LayoutParams.MATCH_PARENT;를 사용해야 할 수도 있습니다. params.height = ViewGroup.LayoutParams.MATCH_PARENT; FrameLayout의 경우. – sandrstar

0

네, 그것은 참으로 가능하다 : 나는 그것을 다음과 같은 방법을 적용됩니다. 애니메이트하고자하는 뷰가 컨테이너 내부에있는 한, 컨테이너에 의해, 예를 들어 LinearLayout 또는 다른 레이아웃이 수행하는 것을 의미합니다. 결론적으로 애니메이션을 적용 할 뷰는 윈도우의 루트 뷰가 아니어야하므로 뷰를 애니메이션화 할 수 있어야합니다. 희망 하시겠습니까?

관련 문제