ScrollView中嵌套ExpandableListView

为了让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

转载于:https://www.cnblogs.com/Liang-Blog/p/5794106.html

你可能感兴趣的:(移动开发)