今天做项目发现 RecyclerView嵌套ListView 只显示一个item, 咋办!
此时我们需要把ListView重写一下onMeasure方法。因为当ListView的Item每次改变时都会调用onMeasure.
自定义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 defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MYListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}