添加2行的GridView的视图 [英] Add view between 2 rows Gridview

查看:112
本文介绍了添加2行的GridView的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView,每行3个元素,当我点击一个项目,一个新的观点来行下方。这有点像在iOS上的一个文件夹的应用程序。我没有找到SO或对谷歌的任何答复。也许你可以给我一些提示。

I have a GridView, with 3 elements per row, and when I click on an item, a new view comes below the row. It's a bit like a folder application on iOS. I didn't find any answer on SO or on Google. Maybe you can give me some hints.

推荐答案

您可以轻松地做到这一点与网​​格布局而与的GridView

You can do this easily with GridLayout but not with GridView.

要找出电网的可用宽度,然后把你的项目,并设置列数,或者设置一个 ViewTreeObserver.OnGlobalLayoutListener (然后可以把你的项目)或延长网格布局,并覆盖 onMeasure(INT widthMeasureSpec,诠释heightMeasureSpec)

To find out the available width of the grid before you place your items and set the number of columns, either set a ViewTreeObserver.OnGlobalLayoutListener (which can then place your items) or extend GridLayout and override onMeasure (int widthMeasureSpec, int heightMeasureSpec).

内容的每一行后插入一行,并设置它的能见度 Visibility.GONE ,它是 columnSpec 的你的网​​格布局的列数。当用户点击一个项目,你可以得到它的信息,填充其下的视图,并展开或动画是知名度切换。

Insert a row after every row of content and set it's visibility to Visibility.GONE and it's columnSpec to the number of columns of your GridLayout. When the user taps an item, you can get it's info, populate the view under it and expand or animate it's visibility toggling.

最后,对于指标,我只想将其添加为隐藏行的孩子,当用户点击该物品,计算出该物品的水平中心,准确地把这一观点的中心,在X轴上的坐标(利润将是该行)。

Finally, for the indicator, I would just add it as a child of the hidden row and, when a user taps the item, calculate the horizontal center of said item and exactly place this view's center on the X axis to that coordinate (margins would be OK for this).

请注意,物品不建议这样做,你就必须实例化每一个项目立即显示非常大的列表,而不管他们是否都适合在屏幕上或没有。不同于的GridView 网​​格布局不是 AbsListView 的子项。

Please note that for very large lists of items this is not recommended as you'll have to instantiate every item to display immediately, regardless if they all fit on the screen or not. Unlike GridView, GridLayout is not a child of AbsListView.

这篇关于添加2行的GridView的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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