【发布时间】:2016-11-14 01:21:59
【问题描述】:
每当我尝试设置 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);
是否需要特定的导入语句才能正确执行?
【问题讨论】:
-
您的布局之一似乎是
RelativeLayout -
LayoutParams和View的类型取决于其父View,而不是它本身。您的LinearLayout似乎在RelativeLayout中,RelativeLayout.LayoutParams也是如此,而不是LinearLayout.LayoutParams。 -
@JuanCruzSoler 我正在修改的布局是线性的。相对布局几乎是所有对象的父级,但我要操作的对象是线性的
标签: java android android-layout android-linearlayout