每当我尝试设置LinearLayout的高度时,我总是会遇到这个异常:
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
这是我的代码:
LinearLayout.LayoutParams hide = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
LinearLayout.LayoutParams show = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100);
driverMainOptions.setLayoutParams(hide);
mapDirections.setLayoutParams(show);
我需要一个特定的导入语句来正确执行吗?
答案 0 :(得分:1)
这应该有效
LinearLayout lLayout = new LineaLayout(context);
LayoutParams params = lLayout.getLayoutParams();
params.height = 200;
params.with = 200;
lLayout.setLayoutParams(parmas);
查看已接受的答案