可以填充“网格状”按列而不是按行查看?
我使用 GridView 显示电视频道列表,使用 SimpleCursorAdapter 从数据库检索频道名称。默认行为是填充左侧网格 ->右上->底部如...
1 2
3 4
5 6
GridView 固定为 2 列,并且如果超出其父级的垂直边界,显然可以垂直滚动。
我有一个用户希望在有效地移动到下一列之前先填充每一列的顶部->底部,我正在考虑拥有固定数量的行,并带有某种可水平滚动的“网格”,例如 9行(固定),没有垂直滚动,2 列可见和水平滚动...
1 10 | 19
2 11 | 20
3 12 | 21
4 13 | 22
5 14 | 23 <-> 19-27 hidden, but columns scrollable horizontally
6 15 | 24
7 16 | 25
8 17 | 26
9 18 | 27
我知道 GridView 本身不能做到这一点,但是是否有一个现有的视图会像这样?如果没有,创建自定义视图的最佳方法是什么?
谢谢。
I'm using a GridView to show a list of TV channels using a SimpleCursorAdapter to retrieve channel name from a db. Default behaviour is to fill the grid left -> right, top -> bottom as in...
1 2
3 4
5 6
The GridView is fixed with 2 columns and obviously is scrollable vertically if it exceeds the vertical bounds of its parent.
I have a user who would prefer each column to be filled top->bottom before moving on to the next so effectively I'm looking at having a fixed number of rows with a 'grid' of some sort scrollable horizontally, example with 9 rows (fixed), no vertical scrolling, 2 columns visible and horizontal scrolling...
1 10 | 19
2 11 | 20
3 12 | 21
4 13 | 22
5 14 | 23 <-> 19-27 hidden, but columns scrollable horizontally
6 15 | 24
7 16 | 25
8 17 | 26
9 18 | 27
I understand GridView itself cannot do this but is there an existing view that would behave like this? If not, what would be the best approach to creating a custom view?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能用 GridView 做到这一点。您必须创建一个自定义视图才能执行此操作。
编辑 - 如果您知道网格项目有多大,则可以抄近路。 GridView 很复杂,主要是因为它处理任何大小的项目并动态加载它们。对您来说更简单的方法可能是:
LinearLayout
的HorizontalScrollView
。行
。while
您仍然有需要布局的项目:LinearLayout
,向其中添加行
或更少的项目。LinearLayout
添加到水平布局中。与“水平 GridView”相比,它有一些缺点:
优点:
You can't do it with GridView. You would have to create a custom view to do this.
Edit - if you know how big your grid items are, you can cut some corners. GridView is complicated mostly because it deals with items of any size and loads them dynamically. An easier way for you might be:
HorizontalScrollView
with a horizontalLinearLayout
inside.rows
.while
you still have items you need to layout:LinearLayout
, addingrows
or less items to it.LinearLayout
to the horizontal one.There are some downsides versus what a "horizontal GridView" would get you:
Upsides: