When switching from: component height, an exception occurs in class conversion as shown in the following figure. I checked it online, as shown below:
These supply parameters toParentOf this view specifying how it shoshould be arranged. There are using subclasses of viewgroup. layoutparams, and these correspond to the different subclasses of viewgroup that are responsible for arranging their children.
So basically, if you are adding a view to another, you must set the layoutparams of the view to the layoutparams type that the parent uses, or you will get a runtime error.
I understand it in this way. If you want to add a view to another layout, you must set the layout parameters of this view to the layout parameter type used by its parent class. That is, to dynamically change the height of a component in the Code, the layout parameter type should be the layout parameter type used by its parent class.
|
For example:
<Linearlayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
<Framelayout
Android: Id = "@ + ID/framelayout01"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
</Linearlayout>
If you want to dynamically change the size of framelayout in the code, write as follows:
Framelayout = (framelayout) convertview. findviewbyid (R. Id. framelayout01 );
Linearlayout. layoutparams FF = new linearlayout. layoutparams (layoutparams. wrap_content, height );
|
Framelayout. setlayoutparams (ff );
Note: The layout parameter type should be linear layout of linearlayout. layoutparams, rather than framelayout. layoutparams.