如何在一个GridView底部内添加额外的空间如何在、空间、GridView

2023-09-04 12:58:06 作者:殇+痛=痛?

我需要帮助增加一个空间里面的GridView在它的底部。这个空间应该是在GridView的最后一个元素下方,在它的内部。这个空间不应该工作象一个余量到下一个元素,它应该是唯一可见的,当用户scrolles到GridView的底部。这样做的原因是一个广告横幅部分地覆盖在GridView的底部。除此之外梗阻,用户应该仍然能够看到在GridView的全部内容,这就是为什么需要在将GridView底部的空间。

I need help to add a space inside a GridView at the bottom of it. This Space should be below the last Element of the GridView, inside of it. This space shouldn't work like a margin to the next element, it should be only visible, when the user scrolles to the bottom of the GridView. The reason for this is an ad banner which partly covers the bottom of the GridView. Besides this obstruction, the user should still be able to see the whole content of the GridView, that's why the space at the bottom of the GridView is needed.

底部 左:广告(蓝色)覆盖的GridView元素(橙色)的一部分;右:广告覆​​盖在GridView 的

left: ad (blue) covers part of GridView elements (orange); right: ad covers the space in the bottom of the GridView

为例,它会看起来怎么样,只是想象空间是在底部,而不是顶部。的

到目前为止,我试图与填充和Marging变量为底的工作,但他们都没有对问题的正确变量。我还可以通过计算器搜索,我发现了一些类似的问题,如:Add额外的空间来一个GridView或ListView 或底部:Adding页脚视图,以多列的GridView中的Andr​​oid?。但是,解决方案似乎不适合我的情况,此外我在寻找内部布局文件,而不是内源$ C ​​$ C溶液(如果有的话,当然)。

So far I tried to work with the Padding and Marging Variables for Bottom, but they are not the right variables for the problem. I also searched through stackoverflow, I found some similar questions like: Add extra space to bottom of a GridView or ListView or: Adding a footer View to a multi-column GridView in Android?. But the solutions doesn't seem to fit my case and furthermore I am searching for a solution inside the layout file and not inside the source code (if there is any of course).

您的帮助是非常AP preciated。

Your help is very much appreciated.

推荐答案

要做到这一点,你想你需要一个底部填充添加到您的的GridView 也禁用 clipToPadding 行为。试试下面的XML code:

To achieve that you want you need to add a bottom padding to your GridView but also disable clipToPadding behavior. Try the XML code below:

<GridView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="50dp"
    android:clipToPadding="false"/>

您还可以,如果你想做到这一点从code。这样做的好处是,你可以计算出动态的code偏移:

You can also do it from code if you want. The benefit is that you can compute the offset dynamically in code:

gridView.setPadding(int left, int top, int right, int bottom);
gridView.setClipToPadding(false);

请注意:如果没有禁用 clipToPadding 的行为,你将最终获得持久的空白区域底部的的GridView ,因此,禁用它是非常重要的。

Note: Without disabling the clipToPadding behavior you will end up with persistent empty area on the bottom of your GridView, so disabling it is very important.

奖金:这里也是关于的ListView 使用 clipToPadding 参数一个很好的链接或的GridView :https://plus.google.com/+AndroidDevelopers/posts/LpAA7q4jw9M

Bonus: Here is also a nice link about using clipToPadding parameter in ListView or GridView: https://plus.google.com/+AndroidDevelopers/posts/LpAA7q4jw9M

 
精彩推荐