Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams

今天在項目中遇到這個問題。上網看看了看,發現也有很多網友遇到同樣的問題。

簡單google了幾篇文章,發現瞭解決方法:

官方API有說明:

http://developer.android.com/reference/android/view/View.html#setLayoutParams%28android.view.ViewGroup.LayoutParams%29

public void setLayoutParams (ViewGroup.LayoutParams params)

Set the layout parameters associated with this view. 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.

Parameters
params The layout parameters for this view, cannot be null
相信英語比我好的都大概看明白這段話的意思。重點是紅色字體部分,
最上層(最頂層)的Layout不需要設定在此值,否則會報標題的錯誤.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章