针对于FrameLayout布局参数的修改
在GLSurfaceView还未成功加载出视频的时候,用户提前进去播放界面查看,这时候不知道 GLSurfaceView所在的FrameLayout的宽高需要调置多少,在知道获取到视频的分辨率为1920*1080后
采用动态设置布局的属性的方法
最开始我使用
//根据设备的宽高调整布局的宽高
int playWidth = pixels[0];
int playHeight = (int)(pixels[0] * (1080/1920f));
//创建一个新的属性
FrameLayout.LayoutParams playLayoutParams = new FrameLayout.LayoutParams(playWidth,playHeight);
//找到目标布局
FrameLayout frameLayout = findViewById(R.id.home_play_layout);
//设置属性
frameLayout.setLayoutParams(playLayoutParams);
结果就报了标题的错误
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
后来我改为
//根据设备的宽高调整布局的宽高
int playWidth = pixels[0];
int playHeight = (int)(pixels[0] * (1080/1920f));
//创建一个新的属性
FrameLayout.LayoutParams playLayoutParams = new FrameLayout.LayoutParams(playWidth,playHeight);
//找到目标布局
FrameLayout frameLayout = findViewById(R.id.home_play_layout);
//设置布局内组件的布局属性
showView.setLayoutParams(playLayoutParams);
就成功了;
如果有人知道第一种写法为什么报错请告知我,感谢