為了讓SrollView中嵌套ExpandableListView,我們就得改ListView的高度,所以寫一個類繼承於ExpandableListview:
import android.content.Context; import android.util.AttributeSet; import android.widget.ExpandableListView; /** * Created by liang on 2016/8/21. */ public class NestedExpandaleListView extends ExpandableListView { public NestedExpandaleListView(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); } }
這樣大概就可以了,以后用到的ExpandableListView就改為NestedExpandaleListView(包括xml文件,activity中用到的地方)就可以了。
參考資料:http://blog.csdn.net/swust_chenpeng/article/details/17413955