我使用的 SDK 提供了一个矩形GLSurfaceView
通过回调。
我希望能够以圆形布局渲染此视图。 (即)我想在圆形视图上显示视图
- 当我叠加时它显示圆形
GLSurfaceView
over ImageView
GLSurfaceView over ImageView
- 当我叠加时它显示方形
GLSurfaceView
over VideoView
.
GLSurfaceView over VideoView
我尝试过下面的代码来制作圆圈GLSurfaceView
public class SampleGLView extends GLSurfaceView implements View.OnTouchListener {
private Path clippingPath;
public SampleGLView(Context context) {
this(context, null);
}
public SampleGLView(Context context, AttributeSet attrs) {
super(context, attrs);
setOnTouchListener(this);
}
private TouchListener touchListener;
@Override
public boolean onTouch(View v, MotionEvent event) {
final int actionMasked = event.getActionMasked();
if (actionMasked != MotionEvent.ACTION_DOWN) {
return false;
}
if (touchListener != null) {
touchListener.onTouch(event, v.getWidth(), v.getHeight());
}
return false;
}
public interface TouchListener {
void onTouch(MotionEvent event, int width, int height);
}
public void setTouchListener(TouchListener touchListener) {
this.touchListener = touchListener;
}
@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);
}
}
问题:
我该如何将其剪切并渲染为圆形?
(背景不断变化,所以我无法在此视频视图之上叠加透明视图。目的是获得一个矩形 glsurface 视图,其顶部有一个圆形 glsurface 视图)
有谁知道如何解决请发表评论。提前致谢。