I hope I can show 3 items in a page of viewpager, but now I only could set viewpager's padding value and margin value, so it only show one item in a page of viewpager. How can I set the item width? I think if I can set more little width of item, the viewpager will show more items in a page.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Have you tried setting the page margins to a negative value, see
setPageMargin(int)
? If I remember correctly, I read someone realizing something similar to what you're describing that way.Alternatively, you could have a look at using a
Gallery
in stead, although I have to admit I'm not a big fan of them as they seem to be less flexible and more buggy.Quick Answer
What you want is overriding
getPageWidth
in thePagerAdapter
implementation you made for thatViewPager
.For example setting it to
0.8f
will make a single page cover only 80% of the viewpagers width so that part of the next and/or previous pages are visible.More information at https://developer.android.com/reference/android/support/v4/view/PagerAdapter.html#getPageWidth(int)
Other remarks
Also note that the negative margins will only cause the separate pages to overlap each other. The margin is used to define the space between each page.
If no alternative pageWidth is configured (there is no setter, only the override) it will cover 100% by default making no part of the other pages visible unless dragged.
Code example
A very nice overview of what is possible can be found here https://commonsware.com/blog/2012/08/20/multiple-view-viewpager-options.html
The view pager in your layout
Example of an inline configured Adapter implementation, this would go in the onCreate or onViewCreated methods:
Example code based on https://newfivefour.com/android-viewpager-simple-views.html