Vertical 'Gridview with pages' or 'Viewpager'
Asked Answered
R

2

3

What I functionally need is a Vertical ViewPager with GridView. So every page of the ViewPager should have a GridView, but the ViewPager is horizontal.

So there are two possibilities:

  • Rotate the ViewPager with GridViews
  • Create a GridView that shows the items in pages

The GridView should show 0-20 when the user scrolls 20-40 etc etc.

Does anyone have a solution for this?

I have checked this link, but I cannot use it cause of legal reasons.

Renick answered 10/7, 2012 at 8:7 Comment(0)
S
4

Sounds like what you really need is a vertical ViewPager. Although Android only provides a horizontal one, there's nothing that prevents you from implementing it yourself. Get the ViewPager source code and modify it to detect swipes up/down instead of left/right. The source is distributed under Apache 2.0 license, therefore you have full rights to create derivative works without having to distribute the source of it.

There will be very few places to change, specifically, methods related to computing the swipe direction/slope (up/down instead of left/right) and methods related to layout computation (using height instead of width and layout pages below each other).

Sandpaper answered 10/7, 2012 at 8:16 Comment(5)
Thanks, that was indeed the best way to do it. It's not that easy to convert it, but I've done it.Renick
@IonAalbers Any chance of open-sourcing your custom implementation?Peyter
@iPaulPro Sorry, cannot do that... Good luck :)Renick
@Archy Burke If you made your custom implementation, is there any chance of open-sourcing it ? :DArchy
@Archy Never ended up making it. Sorry. Be sure to update here if you find/make it yourself.Peyter
M
0

ViewPager2 has been introduced in 2019.

dependencies {
    implementation "androidx.viewpager2:viewpager2:1.0.0"
}

ViewPager2 is the advancer for ViewPager, it does not only support Horizontal paging, Vertical orientation support has been added.

https://developer.android.com/jetpack/androidx/releases/viewpager2

Martie answered 6/5, 2023 at 1:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.