ScrollView中嵌套ExpandableListView

爲了讓SrollView中嵌套ExpandableListView,咱們就得改ListView的高度,因此寫一個類繼承於ExpandableListview:android

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中用到的地方)就能夠了。ide

參考資料:http://blog.csdn.net/swust_chenpeng/article/details/17413955spa

相關文章
相關標籤/搜索