GridView控件与不同的细胞大小,Pinterest的风格 [英] gridView with different cells sizes, pinterest style

查看:203
本文介绍了GridView控件与不同的细胞大小,Pinterest的风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href="http://developer.android.com/reference/android/widget/GridView.html">GridView是一个类,扩展适配器视图的,这意味着它有效地显示在细胞网格式,循环旧观点被显示为新的当用户滚动吧。

GridView is a class that extends AdapterView , which means it shows cells in a grid-style efficiently, recycling old views to be shown as new ones when the user scrolls it.

有时候,你会希望获得一个特殊的UI,这类似于Windows手机瓷砖UI中,在彼此的顶部具有不同尺寸的细胞

Sometimes, you would want to get a special UI, which resembles the Windows Phone Tiles UI, having cells of different sizes on top of each other.

事情是这样的:

AABB
AACC
AADD
AADD

每个字母重新presents其单元的一部分,所以小区A是2X4,小区B和小区C取每个2X1和细胞D为2×2。

each letter represents a part of its cell, so cell A is 2x4 , cell B and cell C take 2x1 each , and cell D is 2x2 .

这可能是比的是,这里小区D完成了一下上面我所展示的,和右侧下方还有另一种细胞使D的端和年底是没有必要的对齐,甚至更多。

It could be even more than that, where cell D finished a bit above what i've shown, and right beneath it there is another cell so the end of D and the end of A aren't necessary aligned.

一个应用程序,具有这种风格的一个例子是 Pinterest的

an example of an app that has this style is pinterest .

GridView控件不允许这样的事情。

GridView doesn't allow such a thing.

其实,每一个解决方案,我已经试过了问题。想问问有没有任何其他的替代品或更好的解决方案。

In fact , every solution I've tried has issues. Would like to ask if there are any other alternatives or better solutions.

有多种方法可以解决这个问题:

There are multiple ways to handle this problem:

  1. 作为扩展<一类href="http://developer.android.com/reference/android/widget/AdapterView.html">AdapterView 的GridView 必须有一个类型为每个项目(使用<一能力href="http://developer.android.com/reference/android/widget/BaseAdapter.html#getItemViewType%28int%29">BaseAdapter),这将允许您设置布局单元格中。

  1. As a class that extends AdapterView GridView has the ability to have a type for each item (using the BaseAdapter), which would allow you to set how to layout the cell .

然而,它仍然限制了你,因为你会得到行项目,一是下的其它。你必须让他们保持一致。

However, it still limits you since you will get rows of items, one beneath the other. you have to have them aligned.

<一个href="http://developer.android.com/reference/android/widget/GridLayout.html">GridLayout是一个相对较新的布局,这是相当灵活的。谷歌已经发布了它一个很好的兼容性,supporing API7以上。

GridLayout is a relatively new layout, and it's quite flexible. Google has published a nice compatibility library for it, supporing API7 and above.

但是,它并没有采用任何意见回收,所以这是一个不错的选择如果你希望显示了很多项目。

However, it doesn't use any recycling of views, so it's a bad choice in case you wish to show a lot of items.

如果你有很多的项目,你需要创建所有的意见他们。

If you have a lot of items, you would need to create all of the views for them .

QuiltView库 - 从网格布局延伸,所以主要有喜欢同样的问题。

QuiltView Library - extends from GridLayout, so basically has the same problem like it.

<一个href="http://www.androidviews.net/2013/01/pinterest-like-adapterview/">StaggeredGridView - 特别是改变方向时,看起来最有前途的,但有一个很大的错误。这样的错误包括空单元格,坏的滚动和NPE(罕见,但仍然发生)。我也不能确定它是否支持具有特定的细胞,而不是单独imageViews。

StaggeredGridView - looks the most promising, but has a lot of bugs, especially when changing orientation. such bugs include empty cells, bad scrolling and NPEs (rare but still happens). I'm also not sure if it supports having customized cells instead of imageViews alone .

其他的解决方案,如提及<一个href="http://www.justinmccandless.com/blog/Pinterest-Style+Staggered+Masonry+List+in+Android">here

other solutions, as mentions here .

有谁知道另一种选择这个问题?也许一些解决方法任我展示?该解决方案

The question

Does anyone know of another alternative to this problem? Maybe some workarounds for any of the solutions I've shown?

编辑:我认为,大约StaggeredGridView,滚动和异常可以通过使用您设置其大小的getView内正常ImageView的解决。我认为,它以一种不可思议的方式工作的原因是,样本更新的ImageView的大小后,这是从网上下载。

I think that about StaggeredGridView , the scrolling and exceptions can be solved by using a normal ImageView that you set its size inside the getView. i think that the reason for it to work in a weird way is that the sample updates the size of the imageview after it was loaded from the internet.

不过,空单元格的问题仍停留在这个库。不仅如此,但它们的尺寸发生很大的变化,即使在不改变方向。

However, empty cells issue still remains in this library. not only that, but their sizes change a lot , even without changing the orientation.

编辑:就目前而言,我认为最好的解决办法是使用, PinterestLikeAdapterView库

for now, i think the best solution is to use , PinterestLikeAdapterView library.

它没有我能找到的任何问题。

it doesn't have any issues that i can find.

然而,它不能使各色需要超过1小区宽度。这是非常好的不过。

however, it can't make items to take more than 1 cell width. it's very good nevertheless.

编辑:不幸的是它有问题notifyDataSetChanged。我已经报道了它<一个href="http://stackoverflow.com/questions/19243670/how-to-avoid-refreshing-of-cells-on-when-calling-notifydatasetchanged-for-pint">here.

sadly it has issues with notifyDataSetChanged . i've reported about it here.

推荐答案

我想的 RecyclerView 与<一个href="https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html"相对=nofollow> StaggeredGridLayoutManager 可以解决这个问题,如果你想也有一个快速滚动,你可以尝试的 这个库

I think a RecyclerView with StaggeredGridLayoutManager can solve this issue, and that if you wish to also have a fast-scroller, you can try this library.

所以,没有更多的绝招需要,为谷歌提供了一个解决方案...

So, no more trick are needed, as Google provided a solution...

这篇关于GridView控件与不同的细胞大小,Pinterest的风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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