Android 5.0的 View
类中新增了 setOutlineProvider(ViewOutlineProvider provider)
方法,注释如下:
Sets the {@link ViewOutlineProvider} of the view, which generates the Outline that defines the shape of the shadow it casts, and enables outline clipping.
The default ViewOutlineProvider, {@link ViewOutlineProvider#BACKGROUND}, queries the Outline from the View’s background drawable, via {@link Drawable#getOutline(Outline)}. Changing the outline provider with this method allows this behavior to be overridden.
If the ViewOutlineProvider is null, if querying it for an outline returns false, or if the produced Outline is {@link Outline#isEmpty()}, shadows will not be cast.
Only outlines that return true from {@link Outline#canClip()} may be used for clipping.
@see #setClipToOutline(boolean)
@see #getClipToOutline()
@see #getOutlineProvider()
那么我们可以用它来把 View
裁剪成一些特定(圆形、矩形、圆角矩形)的形状:
|
|
也可以用来设置投影,但是投影的形状只能是凸多边形,为什么?看源码:
|
|
|
|