activity中加載系統自帶的ExpandableListView;
自定義一個CustomExpandableListView作為ExpandableListView的子Item;
CustomExpandableListView中重寫onMeasure()方法:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
該方法是控制ExpandableListView顯示高度,上面代碼實作了ExpandableListView将所有的Item都顯示,但是有一個問題:
例如:List A的item是CunstomExpandableListView B,B共有10item,則如果B的item也是CustomExpandableListView C,則C展開的item數count1與B能顯示的Item數count2之和為10;
這樣可以實作三級,再多就不會弄了;
注:這本來是要寫一個動态的n層的ExpandableListView但是當子ExpandableListView展開時不能控制好Group的高度;是以放棄了,尋找其他的實作方式;
本文轉自wauoen51CTO部落格,原文連結:http://blog.51cto.com/7183397/1603658 ,如需轉載請自行聯系原作者