How to preset the number of the items(or the percent of the item) that is showing on the screen at a time in HorizontalRecyclerView?

走远了吗. 提交于 2020-01-25 06:41:49

问题


I have HorizontalRecyclerView with images that is being stored locally in Resource. The size of the image is 262dp x 150dp (SVGs).

I want to show 1.5 items at a time on the screen. 1 full Image and the other is 0.5 times. I have achieved it by manipulating the width of the item in oncreateviewholder() of the recyclerview like below:

 int itemWidth = (int)(width / 1.5);

            ViewGroup.LayoutParams layoutParams = ((BannerHolder) holder).bannerImg.getLayoutParams();
            layoutParams.height = layoutParams.height;
            layoutParams.width = itemWidth;
            ((BannerHolder) holder).bannerImg.setLayoutParams(layoutParams);
            ((BannerHolder) holder).bannerImg.setImageResource(bannerList[position]);

But the images are not showing properly. There are white(background color) spaces on the top and bottom of the image and that too depened upon the screen.

  1. Below is the default configurtion.

  1. This is after I explicitly set the width to be 1.5.

It can be seen that there is a space on the left & right side of the image.

Using 1. The images on one screen are different on different screens. And I want to show the image exactly 1.5 independent of the device and the image size.

来源:https://stackoverflow.com/questions/59813559/how-to-preset-the-number-of-the-itemsor-the-percent-of-the-item-that-is-showin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!