可以按列而不是按行填充“网格状”视图? [英] Possible to fill a 'grid-like' view by column rather than by row?

查看:100
本文介绍了可以按列而不是按行填充“网格状”视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GridView来使用SimpleCursorAdapter显示电视频道列表,以从数据库中检索频道名称。

  1 2 $ b $默认行为是填充网格left  - > right,top  - > bottom b 3 4 
5 6

GridView固定为2列,显然可以垂直滚动如果它超出了其父项的垂直边界。



我有一个用户希望每个列都被填充top-> bottom,然后再切换到下一个有效的I '看着有固定数量的行与一个'网格'的某种可水平滚动,例如9行(固定),没有垂直滚动,2列可见和水平滚动...

  1 10 | 19 
2 11 | 20
3 12 | 21
4 13 | 22
5 14 | 23 - 19-27隐藏,但列可水平滚动
6 15 | 24
7 16 | 25
8 17 | 26
9 18 | 27

我理解GridView本身无法做到这一点,但是有没有一个现有的视图会表现得像这样?如果没有,创建自定义视图的最佳方法是什么?



谢谢。

解决方案

你无法用GridView来完成。您必须创建一个自定义视图来执行此操作。



编辑 - 如果您知道网格项目的大小,角落。 GridView很复杂,主要是因为它处理任何大小的项目并动态加载它们。一个更简单的方法可能是:
$ b


  1. 使用水平方向创建一个 Horizo​​ntalScrollView code> LinearLayout 里面。

  2. 确定您的物品有多少行可以放在屏幕上。调用这个 rows

  3. ,而您仍然需要布置项目:


    1. 创建一个垂直 LinearLayout ,添加 rows 或更少项目。

    2. 将新的垂直 LinearLayout 添加到水平线。


    与水平GridView会带给您的一些缺点相比:


    • 所有视图都会立即加载,这对于庞大的物品清单不利。

    • 您需要知道物品有多大,


    上市公司:

    $ ul

  4. 实现起来非常简单。


  5. 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.

    解决方案

    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.

    这篇关于可以按列而不是按行填充“网格状”视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆