问题
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.
- Below is the default configurtion.
- 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