直接嵌套會有問題,要解決這個衝突,只需要重寫ListView,然後給ListView重新測量下就行了。
代碼如下:
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
int newHeightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthSpec, newHeightSpec);
}
經測試,在RecyclerView使用上述方法同樣可以。