opengl的surfaceview使用findViewById返回null问题解决

在进行Android开发时,为了实现使用OpenGL绘制YUV视频数据,作者遇到了在自定义的GLSurfaceView中无法通过findViewById获取View的问题。问题出在自定义的MyGLViewForLogic类构造函数中,错误地调用了只有一个参数的父类构造函数。正确做法应该是使用带有AttributeSet的构造函数。修正构造函数后,问题得到解决。
摘要由CSDN通过智能技术生成

尼玛,搞了一年多引擎,苦逼的我又开始研究起android开发来了

手里有个需求需要使用Opengl 画YUV格式的视频数据,所以就写了小东东,结果丫的就是获取不了view,代码如下

先看代码好了

 

1,继承opengl的surfaceView的类

public class MyGLSurface extends GLSurfaceView {

 private MyGLRender mMyGLRender;


 public MyGLSurface(Context context) {
  super(context);

 }
 
 public MyGLSurface(Context context, AttributeSet attrs) {
  super(context, attrs);
  
 }
 
 public MyGLSurface(Context context, AttributeSet attrs, int defStyle) {
  super(context);//这里这么写也是很不厚道的

 }
}

 

2,再次继承了上面的类,用来处理一些UI以外的逻辑

public class MyGLViewForLogic extends MyGLSurface {

 public MyGLViewForLogic(Context context) {
  super(context);

  initVideoView();
 }
 
 public MyGLViewForLogic(Context context, Attr

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值