1. 程式人生 > >android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

直接導火索:getView返回的view 內容執行了

    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    setLayoutParams(layoutParams);

推送:listView作為容器,子view不能適應ViewGroup.LayoutParams,而是需要abslistView

解決辦法:刪除這個設定

問題發生在4.4.x的手機上

android.widget.ListView.setupChild(ListView.java:1868)

2 android.widget.ListView.makeAndAddView(ListView.java:1823)

3 android.widget.ListView.fillSpecific(ListView.java:1352)

4 android.widget.ListView.layoutChildren(ListView.java:1641)

5 android.widget.AbsListView.onLayout(AbsListView.java:2177)

6 android.view.View.layout(View.java:15184)

7 android.view.ViewGroup.layout(ViewGroup.java:4901)

8 android.widget.FrameLayout.layoutChildren(FrameLayout.java:500)

9 android.widget.FrameLayout.onLayout(FrameLayout.java:435)

10 android.view.View.layout(View.java:15184)

11 android.view.ViewGroup.layout(ViewGroup.java:4901)

12 android.widget.RelativeLayout.onLayout(RelativeLayout.java:1154)