4
以下是我的布局xml中定义我的RelativeLayout的片段。RelativeLayout正在返回LinearLayout LayoutParams
<RelativeLayout
android:id="@+id/npvirrButtons"
android:layout_width="match_parent"
android:layout_height="0dp"
>
<Button
android:id="@+id/buttonNPVLabel"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
<Button
android:id="@+id/buttonIRR_NFV"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
</RelativeLayout>
这里是我保存对它的引用。
this.npvirrButtons = (RelativeLayout)this.findViewById(R.id.npvirrButtons);
再后来,当我尝试改变高度从0dp
到wrap_content
,我抢布局PARAMS这样的:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)this.npvirrButtons.getLayoutParams();
,但我得到抛出的异常:
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
at com.mydomain.myapp.MyActivity.calculateIRR(MyActivity.java:564)
为什么我的RelativeLayout返回一个LinearLayout params对象?
尝试在删除gen&bin文件夹后重新运行项目 –