ViewOutlineProvider -- 视图轮廓
setOutlineProvider--
可以使用View.setClipToOutline方法去剪切一个视图的outline区域。
只有rectangle,circle, 和round rectangle outlines支持裁剪(Outline.canClip方法用来判断是否可以裁剪)
ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() { // @Override public void getOutline(View view, Outline outline) { int size = getResources().getDimensionPixelSize(R.dimen.fab_size); //将视图截成圆角矩形 outline.setOval(0, 0, size, size); } }; //将轮廓提供者与待裁剪的view绑定 fab.setOutlineProvider(viewOutlineProvider);
int margin = Math.min(clippedView.getWidth(), clippedView.getHeight()) / 10; Outline mClip = new Outline(); mClip.setRoundRect(margin, margin, clippedView.getWidth() - margin, clippedView.getHeight() - margin, margin / 2); /* Sets the Outline of the View. */ clippedView.setOutline(mClip); /* Enables clipping on the View. */ clippedView.setClipToOutline(true);