Search code examples
androidkotlinandroid-viewpagerandroid-viewpager2

Can we use ViewPage in wrap content


If I use viewpager in wrap content I always end up with the error

Process: com.example.openinapp, PID: 5144

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

Solution

    1. In my viewpager adapter making the layout programatically match parent will solve this error

    //line added

        ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        return MyViewHolder(view)
    }
    
    1. Second way is by making match parent in XML