Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set ViewPager size

Layout

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?

like image 756
GeminiYellow Avatar asked Nov 02 '12 11:11

GeminiYellow


People also ask

How the ViewPager is implemented?

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 .

How do I set ViewPager height dynamically in Android Kotlin?

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.

How do I stop ViewPager from scrolling?

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.


1 Answers

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.

like image 64
Trung Nguyen Avatar answered Oct 17 '22 16:10

Trung Nguyen