2014-12-13 64 views
0

我正在使用Android示例中的FAB按鈕(1)。 如果我明白它的正確性,實現FAB的擴展FrameLayout的構造器會將該大綱視圖映射到視圖,使視圖實例化時視圖變爲橢圓形。顯示動畫在視圖被剪裁爲輪廓之前啓動

public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr, 
          int defStyleRes) { 
    super(context, attrs, defStyleAttr); 

    setClickable(true); 

    // Set the outline provider for this view. The provider is given the outline which it can 
    // then modify as needed. In this case we set the outline to be an oval fitting the height 
    // and width. 
    setOutlineProvider(new ViewOutlineProvider() { 
     @Override 
     public void getOutline(View view, Outline outline) { 
      outline.setOval(0, 0, getWidth(), getHeight()); 
     } 
    }); 

    // Finally, enable clipping to the outline, using the provider we set above 
    setClipToOutline(true); 
} 

我想OT透露按鈕wheneever活動啓動: 我申請就可以了顯示效果的onWindowFocusChanged活動方法,什麼情況是,動畫開始,僅在其共完成視圖的輪廓被剪輯。

final View fabContainer = findViewById(R.id.create_new_workout_fab); 

       Animation anim = AnimationUtils.loadAnimation(YourWorkouts.this, R.anim.reveal_fab); 
       fabContainer.setVisibility(View.VISIBLE); 

       Animator animator = ViewAnimationUtils.createCircularReveal(
         fabContainer, // view to reveal 
         fabContainer.getWidth()/2, // start X coordinate of reveal 
         fabContainer.getHeight()/2, // start Y coordinate of reveal 
         0, // start radius. In most cases - 0 
         Math.max(fabContainer.getWidth(), fabContainer.getHeight()) // end radius 
       ); 

       // Set a natural ease-in/ease-out interpolator. 
       animator.setInterpolator(new AccelerateDecelerateInterpolator()); 
       fabContainer.setClipToOutline(true); 
       // Finally start the animation 
       animator.start(); 

所以,當揭示動畫運行時,視圖不是橢圓形,並且在揭示動畫結束後變成橢圓形。 如代碼中所示,我也嘗試在開始動畫之前手動設置剪輯,但它不起作用。

有人可以幫我嗎?

回答