一. 重写ExpandableListView
/**
*
* 自定义ExpandableListView 解决嵌套之下显示不全的问题
*/
public class CustomExpandableListView extends ExpandableListView {
public CustomExpandableListView(Context context) {
super(context);
}
public CustomExpandableListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 解决显示不全的问题
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2
, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
二. 修改ListViewAdapter
-
getChildrenCount() 返回1
-
getChildView() 返回的是ExpandableListView对象。
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
CustomExpandableListView eListView = getExpandableListView();
List<Item> childData = new ArrayList<Item>();
childData.addAll(getChildData(groupPosition));
// 嵌套第三层的适配器
PackageChildListAdapter packageChildListAdapter = new PackageChildListAdapter(mContext, childData);
eListView.setAdapter(packageChildListAdapter);
return eListView;
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。