1. 程式人生 > >RecyclerView中item巢狀RecyclerView不顯示問題

RecyclerView中item巢狀RecyclerView不顯示問題

在巢狀時要給巢狀的RecyclerView設定寬高,否則不顯示

/**
 * 重設item的高度
 */
private void resetRecyclerHeight(int type, int size) {
    ViewGroup.LayoutParams layoutParams = item_recyclerview.getLayoutParams();
layoutParams.width = RecyclerView.LayoutParams.MATCH_PARENT;
    if (type == 1) {
        int coverWidth = (GlobleData.screenWidth 
- Uitl.dip2px(getContext(), 78)) / 4; //單個圖片高 int coverHeight = coverWidth * 9 / 16; layoutParams.height = coverHeight * size; } else { layoutParams.height = ((GlobleData.screenWidth - Uitl.dip2px(getContext(), 100)) / 6) * size; } item_recyclerview.setLayoutParams(layoutParams); }