在使用横向RecyclerView 时,有一个需要是屏幕可见区域只显示3个item,可以在Adpter中修改item宽度如下【红色部分】:
recyclerOxygen.setAdapter(new CommonAdapter<String>(getActivity(), R.layout.item_record_sub, oxygen) {
@Override
public void convert(ViewHolder holder, String s) {
//holder.getView(R.id.tv_1).setMax(holder.getView(R.id.ll_root).getWidth()/3);
ViewGroup.LayoutParams layoutParams = holder.getView(R.id.ll_root).getLayoutParams();
layoutParams.width = (ScreenUtils.getScreenWidth() - DpPxUtil.dp2px(getActivity(), 70)) / 3;//
holder.getView(R.id.ll_root).setLayoutParams(layoutParams);
holder.setText(R.id.tv_1, s);
}
});