Recycleview 在头布局里嵌套Listview

1.自定义Mylistview集成Listview

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

    public MyListView(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);
    }
}

重写onMeasure() 解决listview显示不全的问题;

2.在代码中设置:

 ll_list = (MyListView) mHeadview.findViewById(R.id.ll_list);
ll_list.setFocusable(false);
ll_list.setEnabled(false);

设置setFocusable(false)和setEnabled(false);解决下拉滑动时在listview卡顿问题;

你可能感兴趣的:(自定义view)