Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal recycler view with width less than match_parent

Have a horizontal recyclerview. Want the width to be less than match_parent only able to view some pixels of the next item. Is there a way to do this?

enter image description here

like image 545
vijaydev Avatar asked Jan 05 '23 19:01

vijaydev


1 Answers

First of all get the screen width.

DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowmanager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
windowmanager.getDefaultDisplay().getMetrics(displayMetrics);
int deviceWidth = displayMetrics.widthPixels;

Then in your adapter fix the width of your view:-

item_width = deviceWidth - (deviceWidth/100 * 10);
like image 92
gourav sarswa Avatar answered Feb 26 '23 19:02

gourav sarswa