CardSlider icon indicating copy to clipboard operation
CardSlider copied to clipboard

java.lang.IllegalStateException: Pages must fill the whole ViewPager2 (use match_parent)

Open MahmoudMabrok opened this issue 4 years ago • 2 comments

MahmoudMabrok avatar Apr 02 '20 16:04 MahmoudMabrok

Hello, Same problem. My Code; java.lang.IllegalStateException: Pages must fill the whole ViewPager2 (use match_parent) at com.github.islamkhsh.viewpager2.ViewPager2$2.onChildViewAttachedToWindow(ViewPager2.java:205)

CeRBeR666 avatar Apr 02 '20 19:04 CeRBeR666

@CeRBeR666 solution is to make item_view of adapter to has match_parent for both width, height this worked with me.

MahmoudMabrok avatar Apr 02 '20 20:04 MahmoudMabrok

I still had the same problem, because I was using the ViewBinding. If you go with raw implementation like

public class BannerHolder extends RecyclerView.ViewHolder{ public BannerHolder(@NonNull @NotNull View itemView) { super(itemView); } } It will work.

However if you try to use View Binding like this in adapter: public BannerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { return new BannerHolder(ItemBannerBinding.inflate(LayoutInflater.from(parent.getContext()))); }

This won't work. Hope you understand the change, if you still got the error like me, and got no where to go!

sufyan-info avatar Dec 02 '22 22:12 sufyan-info

i will close the issue as it did not occur after make height and width as match parent.

MahmoudMabrok avatar Dec 03 '22 13:12 MahmoudMabrok

@MahmoudMabrok the library is really great. Thank you all the contributors.

Can you please at least do additional logs for this issue? Because if we use viewBinding for the item_view, and the item_view's LayoutParams is of course both match_parent, this issue still occurs. Do you have any thoughts? Or at least do some logs, where we find the view class that was received by the renderer? And log the found width and height?

Thanks again.

sufyan-info avatar Dec 03 '22 17:12 sufyan-info

it does not occur to me, also I do not have access to the code to try, sorry for this. I have faced this issue for a long time and solved it at that time. so I closed this issue.

MahmoudMabrok avatar Dec 04 '22 16:12 MahmoudMabrok