ListView 自定义item布局 android.widget.LinearLayout$LayoutParams

来源:互联网 发布:中世纪2优化九国家简介 编辑:程序博客网 时间:2024/05/16 13:04

 


 


如果对外层的 Layout设置属性的话, 

lnLayout.setLayoutParams(new LinearLayout.LayoutParams(

      ViewGroup.LayoutParams.FILL_PARENT, android.R.attr.listPreferredItemHeight));


则会报错。。。如上的错误信息,,具体的如下

解决办法就是取消对其中的设置


 



看到http://hi.baidu.com/ljlkings/blog/item/86ed2401029b4efd08fa9303.html


受到了一点启发 :


Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
2010-12-21 17:38

 

These supply parameters to the parent of this view specifying how it should be arranged. There are many 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.

 

 

就是說你要設置此layoutparameters須對父對象佈局設定,最上層的layout不需設定此項。

 

原创粉丝点击