我正在创建一个简单的应用程序,我有一个ExpandableListView。该应用程序可以正常使用ExpandableListView。但是,当我将另一个ListView作为标题视图添加到ExpandableListView时会出现问题。
ListView headerlv = new ListView(this);
String[] newNames = {"Kung Fu Panda 3","Inception","Zootopia","Fantastic Beasts"};
headerlv.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,R.id.lblListItem,newNames));
expListView.addHeaderView(headerlv);
在上面的代码中,expListView是新创建的ListView附加到的父视图。但是,ListView只显示一个项目。如何告诉ListView拉伸并包含所有列表项。需要帮助
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f4f4f4" >
<ExpandableListView
android:id="@+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</LinearLayout>
list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
<TextView
android:id="@+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />
</LinearLayout>