避免在SrollView里面嵌套的ListView或者ExpandableListView无法全部展示数据

package com.lanbang.material.views;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**  * 重写ListView,避免在SrollView里面的ListView无法全部展示数据,(避免只能展示一行,必须靠滚动条来滚动查看所有数据)  *  *  */ public class ListViewForScrollView extends ListView {
    public ListViewForScrollView(Context context) {
        super(context);
    }

    public ListViewForScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ListViewForScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    /**  * 重写该方法,达到使ListView适应ScrollView的效果  *  */  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

如果是ExpandableListView ,只需要把ListView 修改为ExpandableListView。因为ExpandableListView是ListView的子类。亲测,可以解决嵌套导致的listview显示不全,listview滚动图标出现等问题。

你可能感兴趣的:(ListView,scrollview)