I solved Horizontal scroll by this approach:
public void HorizontalSwipe (AndroidDriver driver,int times,double percentage)
{
Dimension size =driver.manage().window().getsize();
int height = size.getHeight();
int width= size.getWidth();
int y=(int)(height * percentage);
int startx=(int)(width * 0.75);
int endx=(int)(width * 0.20);
for(int i=0;i<times;i++)
{
driver.swipe(startx,y,endx,y,1000);
}
Usage:
HorizontalSwipe(driver,3,0.40);
3 -No of times to be scrolled
Here 0.40 means 40% of screen Height(Y axis)
Y axis can be calculated based on 0 to 100 percentage scale ,where Y axis must be changed depend on height.
For Example:
Attached screenshot we have Category Chicken which comes under 40% of screen height.