如何把里面的GridView的滚动型 [英] How to put GridView inside ScrollView

查看:125
本文介绍了如何把里面的GridView的滚动型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要设计布局,使得整个布局应滚动和内部布局我要显示在电网相关的内容的形式,所以我决定用 GridView控件。但问题是,我无法使用的GridView 滚动型我有阅读文档(文档也说,我们不应该使用的GridView 滚动型)also.But我不得不这样做,因此可以在任何请给我约this.Thanks一些想法

I have to design layout such that whole layout should scroll and inside layout I have to display related content in Grid form so I decided to use GridView.But problem is that I’m unable to use GridView inside ScrollView I have read documentation(Documentation also saying that we should not use GridView inside ScrollView) also.But I have to do this,so can any please give me some idea about this.Thanks

推荐答案

有一定好处的内在滚动旁边一个GridView。例如,基于数据的单元格,将扩大与合同一致,动态的布局传递到它。所以,当人们说这不是好渴望这样一个功能,我认为这是错误的,因为你能想到的图像(意见)的动态网格滚动视图里面,但希望是整个滚动视图包含的不仅仅是网格中的其他事情细胞。

There are definitely benefits to a GridView beside the inherent scrolling. For example, a consistent, dynamic layout of cells that will expand and contract based on the data you pass into it. So, when people say it's not good to desire such a functionality, I think that's wrong because you could want the dynamic grid of images (views) inside of a scrolling view, but want that entire scrolling view to contain other things than just the grid cells.

现在,这里是你如何能做到这一点。这里核对答案。这是一个高度可扩展GridView控件,您将要导入/创建项目。什么,基本意思是,随着更多的项目被添加到GridView,它将只扩大它的高度,而不是保持它的高度设置,并使用滚动。这正是你想要的。

Now, here is how you can do this. Check the answer here. It is an expandable height GridView, which you will want to import / create in your project. What that basically means is that as more items are added to the GridView, it will just expand its height, as opposed to keeping its height set and using scrolling. This is exactly what you want.

一旦你在你的项目中ExpandableHeightGridView,去你想要的GridView控件是你的XML布局。然后,您可以做这样的事情(意译):

Once you have the ExpandableHeightGridView in your project, go to your XML layout where you want the GridView to be. You can then do something like this (paraphrasing):

<ScrollView ...>
    <RelativeLayout ...>
        <com.example.ExpandableHeightGridView ... />
        <other view items />
    </RelativeLayout>
</ScrollView>

然后,在你的活动,您可以设置GridView的适配器,你要确保你将它扩大。所以:

Then, in your activity where you set the GridView's adapter, you want to make sure you set it to expand. So:

ExpandableHeightGridView gridView = (ExpandableHeightGridView) findViewById(R.id.myId);
gridView.setAdapter(yourAdapter);
gridView.setExpanded(true);

您想要这个扩展GridView控件的原因是因为,事实上,一个标准的GridView不扩张是什么原因导致它滚动。它坚持到一定的高度,然后随着更多的项目填满它过去的观点界限,它成为滚动。现在,有了这个,你的GridView将随时扩展它的高度,以适应在它的内容,因此永远不会允许它进入滚动模式。这使您可以使用它的滚动型的内部和滚动型中使用高于或低于它的其他视图元素,并把它们都滚动。

The reason you want this expandable GridView is because, the fact that a standard GridView doesn't expand is what causes it to scroll. It sticks to a certain height, and then as more items fill it past its view bounds, it becomes scrollable. Now, with this, your GridView will always expand its height to fit the content within it, thus never allowing it to enter its scrolling mode. This enables you to use it inside of the ScrollView and use other view elements above or below it within the ScrollView, and have them all scroll.

这应该给你你正在寻找的结果。让我知道,如果你有任何问题。

This should give you the result you're looking for. Let me know if you have any questions.

这篇关于如何把里面的GridView的滚动型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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