设置SurfaceView圆角
/**
* 设置Surfaceviewl圆角
*/
private void setSurfaceviewCorner(final float radius) {
mSurfaceView.setOutlineProvider(new ViewOutlineProvider() {
@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, radius);
}
});
mSurfaceView.setClipToOutline(true);
}
为SurfaceView设置渐变蒙层,设置foreground属性
<com.example.myapplication.CustomSurfaceView
android:id="@+id/sv_test"
android:layout_width="500dp"
android:layout_height="500dp"
android:foreground="@drawable/test_gradient" />
test_gradient.xml为上下往中间的渐变效果代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#60000000"
android:centerColor="#20000000"
android:endColor="#60000000"
android:angle="90" />
</shape>```