Could I set the viewpager's size? like the image1, I want to show 3-page in the same screen.
If not, I can only use LinearLayout?
Implement Swipe Views You can create swipe views using AndroidX's ViewPager widget. To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .
Create a custome widget for viewpager class. and in xml use it for viewpager. Then in the view pager adapter override the below method and add the code. Make your view pager height wrap_content inside xml file so you can check the result.
A simple solution is to create your own subclass of ViewPager that has a private boolean flag, isPagingEnabled . Then override the onTouchEvent and onInterceptTouchEvent methods. If isPagingEnabled equals true invoke the super method, otherwise return . Save this answer.
Your problem is similar to one CommonWare's blog. Multiple-View ViewPager Options
There are three approach. One of those is override getPageWidth()
in your PagerAdapter:
@Override public float getPageWidth(int position) { return(0.5f); }
The others are more complicated but there're attach source and long explanation so i don't copy here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With