掩码和剪辑GLSurfaceView

时间:2015-03-03 11:17:42

标签: android android-layout opengl-es mask glsurfaceview

我使用SDK,通过回调提供矩形glsurfaceview。

我希望能够以圆形布局呈现此视图。 (即)我想在圆形视图上显示视图

我尝试过使用蒙版布局,例如使用可屏蔽布局https://github.com/christophesmet/android_maskable_layout(非常适合图像使用,而不是视频)

如何剪裁并将其渲染为圆圈?

(背景不断变化,所以我无法在此视频视图的顶部覆盖透明视图。目的是在其上方有一个矩形的glsurface视图,其中有一个圆形的glsurface视图)

** UI目标:** enter image description here

1 个答案:

答案 0 :(得分:0)

我现在对项目的要求几乎相同,其中包括屏蔽PexKit提供的GLSurfaceView。适合我的解决方案是创建FrameLayout(或任何其他ViewGroup)的子类,并将GLSurfaceView放在其中。

然后在FrameLayout子类中使用canvas.clipPath:

private Path clippingPath;

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    if (w != oldw || h != oldh) {
        int radius = Math.min(w, h)/2;
        clippingPath = new Path();
        clippingPath.addCircle(w/2, h/2, radius, Path.Direction.CW);
    }
}

@Override
protected void dispatchDraw(Canvas canvas) {
    int count = canvas.save();
    canvas.clipPath(clippingPath);
    super.dispatchDraw(canvas);
    canvas.restoreToCount(count);
}