1、新建类继承ViewOutlineProvider
public class TextureVideoViewOutlineProvider extends ViewOutlineProvider {
private float mRadius;
public TextureVideoViewOutlineProvider(float radius) {
this.mRadius = radius;
}
@Override
public void getOutline(View view, Outline outline) {
Rect rect = new Rect();
view.getGlobalVisibleRect(rect);
int leftMargin = 0;
int topMargin = 0;
Rect selfRect = new Rect(leftMargin, topMargin,
rect.right - rect.left - leftMargin, rect.bottom - rect.top - topMargin);
outline.setRoundRect(selfRect, mRadius);
}
}
2、给TextureView设置OutlineProvider即可
mTextureView = view.findViewById(R.id.texture_view);
//圆角 DisplayUtil.dip2px(4) 4dp
mTextureView.setOutlineProvider(new TextureVideoViewOutlineProvider(DisplayUtil.dip2px(4)));
mTextureView.setClipToOutline(true);