FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams问题的解决

针对于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);

就成功了;

如果有人知道第一种写法为什么报错请告知我,感谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值