标签:android blog http ar io sp java on div
有时候需要在在代码中设置LayoutParams,自己为一个FrameLayout设置LayoutParams的时候,遇上如题问题,
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
简单的举个栗子说明一下:最外层有ReLativeLayout A,里面有两个LinearLayout B、C,而B中又有一个一个FrameLayout D。如果要在代码里设置B的LayoutParams,B的LayoutParams要为RelativeLayout.LayoutParams。
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
B.setLayoutParams(params);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
params.weight = 8;
D.setLayoutParams(params);
android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
标签:android blog http ar io sp java on div
原文地址:http://www.cnblogs.com/Free-Thinker/p/4169717.html