RecyclerView 加載圖片列表的時(shí)候,使圖片的寬度為手機(jī)屏幕寬度褂删,高度自適應(yīng)
adapter item布局
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
在adapter里面設(shè)置圖片的寬高
int screenWidth = ((FragmentActivity) mContext).getWindowManager().getDefaultDisplay().getWidth();
ViewGroup.LayoutParams lp = ivImg.getLayoutParams();
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
lp.width = screenWidth;
ivImg.setLayoutParams(lp);
ivImg.setMaxWidth(screenWidth);
ivImg.setMaxHeight(screenWidth * 5); //這里設(shè)置圖片最大的高度