我有一个 ExpandableListView,每个组都有一个孩子。每个孩子都是另一个具有不同行数的 ListView。展开状态下的 ExpandableListView 项目高度存在问题,它没有包裹到子 ListView 内容。我只能在子列表视图布局中设置一个具体的高度值。但我想让 ExpandableListView 自动包装每个孩子。可能吗?
getChildView(
) 来自我的ExpandableListAdapter
:
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if( convertView == null ) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
convertView = inflater.inflate( R.layout.anit_object_data, parent, false );
}
ListView lv = (ListView)convertView.findViewById( R.id.listData );
List<ListData> valuesList = getItems().get(groupPosition).getListData( getContext() );
ListDataAdapter adapter = new ListDataAdapter( getContext(), android.R.layout.simple_list_item_1, valuesList );
lv.setAdapter(adapter);
return convertView;
}
子 ListView 的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id = "@+id/listHolder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="40dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ListView
android:id="@+id/listData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:scrollbars="none" >
</ListView>
</LinearLayout>
</LinearLayout>
我试图在适配器的 getChildView() 中测量子 ListView 的高度,但 ExpandableListView 展开的项目高度仍然不正确。
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if( convertView == null ) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
convertView = inflater.inflate( R.layout.anit_object_data, parent, false );
}
ListView lv = (ListView)convertView.findViewById( R.id.listData );
List<ListData> valuesList = getItems().get(groupPosition).getListData( getContext() );
ListDataAdapter adapter = new ListDataAdapter( getContext(), android.R.layout.simple_list_item_1, valuesList );
lv.setAdapter(adapter);
lv.measure( MeasureSpec.EXACTLY, MeasureSpec.UNSPECIFIED );
convertView.getLayoutParams().height = lv.getMeasuredHeight();
return convertView;
}