我正在使用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);
}
我希望在活动开始时显示按钮: 我在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();
因此,当揭示动画运行时,视图不是椭圆形的,并且在揭示动画结束后变为椭圆形。 如代码所示,我也尝试在开始动画之前手动设置剪辑,但它没有帮助。
有人可以帮帮我吗?
答案 0 :(得分:0)
我很遗憾你不能同时做这两件事:
任何时候都只能在视图上应用一个非矩形剪辑。由圆形显示剪辑剪切的视图优先于视图轮廓剪切。
https://developer.android.com/reference/android/view/ViewAnimationUtils.html
我试图通过添加可绘制的形状背景来伪造它。