Scroll the VerticalGridView by keeping focus on center element. I am implementing a verticalgridview with 1 column count and I want to keep the focus on a single item which is in center and move the verticalgridview.I want to set focus on center object in vertical grid view and scroll the view by fixing the focus there
-
not enough details – Pradip Vadher Jul 08 '19 at 11:59
-
2@Yashwant Welcome to SO, could you elaborate on what you're trying to achieve and what you envision your end result to be? – Chrisvin Jem Jul 08 '19 at 12:02
-
@ChrisvinJem I added a image of what I want to achieve. Please check! – Yashwant Vadali Jul 08 '19 at 15:48
-
@PradipVadher I added a image of what I want to achieve. Please check! – Yashwant Vadali Jul 08 '19 at 15:48
1 Answers
VerticalGridView contains its built-in layout manager which does exactly that. Do NOT use verticalGridView.setLayoutManager(new LinearLayoutManager())
, which one would usually do with RecyclerView. By default the focused item of a VerticalGridView is always positioned at the center unless the item is at the beginning/end, or there are too few items.
If there are too few items, you can use verticalGridView.setWindowAlignment(WINDOW_ALIGN_NO_EDGE)
. Now the items at the beginning/end will also be positioned at the center. You can also choose WINDOW_ALIGN_LOW_EDGE
or WINDOW_ALIGN_HIGH_EDGE
depending on your needs. The default is WINDOW_ALIGN_BOTH_EDGE
.
You can also use verticalGridView. setWindowAlignmentOffsetPercent (offsetPercent)
to manually determine the focus position. If offsetPercent
is 50, the focus is at the center; if it's 90, it's towards the bottom; if it's 10, it' near the top, etc.

- 167
- 2
- 10