How to set recycler view item width size base on screen size?
Your Recyclerview should take a LayoutManager with Column Span size Specified in it. which is something like this:
mList.setLayoutManager(new GridLayoutManager(getContext(), 2));
So now you just need to manage Height of the Items. right? This will do:
@Override
public myViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View myView = inflater.inflate(R.layout.item_home, parent, false);
GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) myView.getLayoutParams();
params.height = (parent.getMeasuredHeight() / 2) - dim24;
myView.setLayoutParams(params);
return new myViewHolder(myView);
}
So.
this (parent.getMeasuredHeight() / 2) - dim24
is where you can adjust your view "HEIGHT"
And dim24
is just a padding Integer, you can get rid of it
Notice I used "2" Columns so I devided item Heights by "2"