可以填充“网格状”按列而不是按行查看?

发布于 2024-10-24 02:08:57 字数 547 浏览 2 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演多会厌 2024-10-31 02:08:57

你不能用 GridView 做到这一点。您必须创建一个自定义视图才能执行此操作。

编辑 - 如果您知道网格项目有多大,则可以抄近路。 GridView 很复杂,主要是因为它处理任何大小的项目并动态加载它们。对您来说更简单的方法可能是:

  1. 创建一个内部带有水平LinearLayoutHorizo​​ntalScrollView
  2. 确定屏幕上适合显示项目的行数。将此称为
  3. while 您仍然有需要布局的项目:
    1. 创建一个垂直 LinearLayout,向其中添加 或更少的项目。
    2. 将新的垂直 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:

  1. Create a HorizontalScrollView with a horizontal LinearLayout inside.
  2. Determining how many rows of your item will fit on the screen. Call this rows.
  3. while you still have items you need to layout:
    1. Create a vertical LinearLayout, adding rows or less items to it.
    2. Add your new vertical LinearLayout to the horizontal one.

There are some downsides versus what a "horizontal GridView" would get you:

  • All the views are loaded up immediately, which is bad for huge lists of items.
  • You need to know how big your items are, and they need to be the same size.

Upsides:

  • It's very easy to implement.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文