When you set layout parameters for the view in getview of the adapter, use the following method:
Layoutparams Params =NewLayoutparams (layoutparams. fill_parent ,(Int) (Metrics. heightpixels * 0.23f + 0.5f); Convertview. setlayoutparams (Params );
ProgramAn error occurs.
06-08 15:39:43. 071: E/androidruntime (610 ): Java. Lang. classcastexception: Android. View. viewgroup $ layoutparams 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. listview. setupchild (listview. Java: 1688 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. listview. makeandaddview (listview. Java: 1661) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. listview. filldown (listview. Java: 637 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. listview. fillfromtop (listview. Java: 694 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. listview. layoutchildren (listview. Java: 1516 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. abslistview. onlayout (abslistview. Java: 1112 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. View. View. layout (view. Java: 6569 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. linearlayout. setchildframe (linearlayout. Java: 1119 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. linearlayout. layouthorizontal (linearlayout. Java: 1108 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. linearlayout. onlayout (linearlayout. Java: 920 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. View. View. layout (view. Java: 6569 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. linearlayout. setchildframe (linearlayout. Java: 1119 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. linearlayout. layoutvertical (linearlayout. Java: 998) 06-08 15:39:43. 071: E/androidruntime (610): at Android. widget. linearlayout. onlayout (linearlayout. Java: 918 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. View. View. layout (view. Java: 6569 ) 06-08 15:39:43. 071: E/Android Runtime (610): at Android. widget. framelayout. onlayout (framelayout. Java: 333 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. View. View. layout (view. Java: 6569 ) 06-08 15:39:43. 071: E/Android Runtime (610): at Android. widget. framelayout. onlayout (framelayout. Java: 333 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. View. View. layout (view. Java: 6569) 06-08 15:39:43. 071: E/androidruntime (610): at Android. View. viewroot. javasmtraversals (viewroot. Java: 979 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. View. viewroot. handlemessage (viewroot. Java: 1613 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. OS. handler. dispatchmessage (handler. Java: 99 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. OS. Looper. Loop (Looper. Java: 123 ) 06-08 15:39:43. 071: E/androidruntime (610): at Android. App. activitythread. Main (activitythread. Java: 4203 ) 06-08 15:39:43. 071: E/androidruntime (610): At java. Lang. Reflect. method. invokenative (native method) 06-08 15:39:43. 071: E/androidruntime (610): At java. Lang. Reflect. method. Invoke (method. Java: 521 ) 06-08 15:39:43. 071: E/androidruntime (610): At com. Android. Internal. OS. zygoteinit $ methodandargscaller. Run (zygoteinit. Java: 791 ) 06-08 15:39:43. 071: E/androidruntime (610): At com. Android. Internal. OS. zygoteinit. Main (zygoteinit. Java: 549)
However, when the settings are as follows:
Viewgroup. layoutparams Param =Convertview. getlayoutparams (); Param. Height= (Int) (Metrics. heightpixels * 0.20f + 0.5f); Convertview. setlayoutparams (PARAM );
OK.
The same is true in http://philn.blog.163.com/blog/static/104014753201101810573338/.
It is no problem to use the initial method when setting layoutparams for linearlayout.
I do not know what to do for the time being?