When inheriting the baseadapter, when getview is used to return the viewCodeView is required to control the layout. setlayoutparams, but an error is reported. The type conversion error is reported. After research, we found that viewgroup cannot be used here. layoutparams must use the layoutparams type of the parent view. For example, if a view is included by linearlayout, The setlayoutparams parameter type of the view must be linearlayout. layoutparams. The reason is that linearlayout (or other layout inherited from viewgroup, such as relativelayout) will obtain the layoutparams of the sub-view and forcibly convert it to linearlayout. layoutparams, as shown in figure
1 Linearlayout. layoutparams lp=(Linearlayout. layoutparams) child. getlayoutparams ();
Or the following definition:
1 Layoutparams lp=(Layoutparams) child. getlayoutparams ();
To convert to the internal linearlayout. layoutparams type.