我是靠谱客的博主 善良煎蛋,这篇文章主要介绍java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.R,现在分享给大家,希望可以做个参考。
错误代码:
ImageView img1 = (ImageView) findViewById(R.id.icon);
img1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
解决办法:
ImageView img1 = (ImageView) findViewById(R.id.icon);
img1.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
根据布局修改,比如布局为
RelativeLayout
则使用
new RelativeLayout.LayoutParams
最后
以上就是善良煎蛋最近收集整理的关于java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.R的全部内容,更多相关java.lang.ClassCastException:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复