转载 

android ScrollView嵌套ListView导致 listview添加了多条数据只显示1个

分类:android    399人阅读    IT小君  2018-10-27 23:00

1、重写ListView 在onMesure中 向父类申请 尽可能多的把空间给ListView 

2、code

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


public class MyListView extends ListView {
    public MyListView(Context context) {
        super(context);
    }


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


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


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

}


支付宝打赏 微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

 工具推荐 更多»