Toolbar 축소된 애니메이션

2275 단어
/** * getViewTreeObserver view  *  view  onCreate , View onResume  *  , view  * addOnPreDrawListener: *  ,  */
mToolbar.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {    
@Override    
public boolean onPreDraw() {
   mToolbar.getViewTreeObserver().removeOnPreDrawListener(this);       
   final int widthSpec=View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);   
   final int heightSpec=View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); 
   mToolbar.measure(widthSpec, heightSpec);    
   mToolbarHeight = mToolbar.getHeight();       
 /***  
      Toolbar 
  **/      
   collapseToolbar();       

   return true;    }
});

collaspseToolbar

public void collapseToolbar() {  
  int targetHeight = 0;   
 TypedValue value = new TypedValue();   
 if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize,value,true)){    
// toolbar       
  targetHeight=TypedValue.complexToDimensionPixelSize(value.data, getResources().getDisplayMetrics());  }    
// toolbar toolbar     
ValueAnimator valueAnimator=ValueAnimator.ofInt(mToolbarHeight, DeviceUtils.dip2px(getActivity(),120));    
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {   
@Override       
 public void onAnimationUpdate(ValueAnimator animation) {          
  // Toolbar           
  ViewGroup.LayoutParams lp = mToolbar.getLayoutParams(); 
  lp.height =(Integer) animation.getAnimatedValue();
//   toolbar, toolbar   
   Log.d("TAG","animator size : "+animation.getAnimatedValue()); 
   mToolbar.setLayoutParams(lp);          
   mToolbar.invalidate();       
 }  
});    
valueAnimator.setDuration(2000);    
valueAnimator.start();    
valueAnimator.addListener(new AnimatorListenerAdapter() {      
  @Override       
 public void onAnimationEnd(Animator animation) {      
      super.onAnimationEnd(animation);            
// toolbar             
   mPresenter.loadWeatherData(mRecycle); 
   YoYo.with(Techniques.ZoomIn).delay(600).duration(400).playOn(mFab);    
      /*  // Animate fab           
   ViewCompat.animate(mFab).setStartDelay(600).setDuration(400).scaleY(1).scaleX(1).start();*/        } 
   });
}

좋은 웹페이지 즐겨찾기