周围的GridView删除多余的空间编程 [英] Remove extra space around GridView programmatically
问题描述
我试图做一个GridView编程在我的Java类,这一切工作正常。问题是各地的GridView控件自动生成的5像素。在XML我设法删除它使用:
的android:listSelector =@空
但我不设法做在java中类似的事情。我已经尝试了一些解决方法就像一个没有运气makeing GridView的10个像素越大,那么实际的屏幕。
没有人有任何code这个?
编辑:
由我的answear不解决问题。还有一个赏金去。
这里是我的GridView code:
GridView控件的GridView =新的GridView(本);
gridView.setLayoutParams(新GridView.LayoutParams(customValue,LayoutParams.FILL_PARENT,Gravity.CENTER_HORIZONTAL));
gridView.setNumColumns(someInt);
gridView.setAdapter(新MyCustomAdapter(本));
-
,以确保填充的一种方式出现在不同的密度的屏幕同样是将其转换成DIP单位。
INT填充= TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,-5,
。getResources()getDisplayMetrics()); -
您可以尝试其他的事情是在XML中定义一个空的绘制。
<?XML版本=1.0编码=UTF-8&GT?;
<资源>
<绘制NAME =null_drawable> @空< /绘>
...
< /资源>然后调用
setSelector(R.drawable.null_drawable);
更新:的
-
定义你的
GridView控件
在其自己的XML和它充气。的布局/ mygrid.xml 的
<?XML版本=1.0编码=UTF-8&GT?;
< GridView控件
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:listSelector =@空/>在Java中,
GridView控件的GridView =(GridView控件)inflater.inflate(R.layout.mygrid,NULL);
gridView.setLayoutParams(新GridView.LayoutParams(customValue,
LayoutParams.FILL_PARENT));
gridView.setNumColumns(someInt);
gridView.setAdapter(新MyCustomAdapter(本));
I am trying to make a GridView programmatically in my java class and it all works fine. The problem is the autogenerated 5 pixel padding around the GridView. In xml I manage to remove it using:
android:listSelector="@null"
But I do not manage to do anything similar in java. I have tried some workarounds like makeing the GridView 10 pixels larger then the actual screen with no luck.
Does anyone have any code for this?
Edit:
The answear by me does not solve the problem. There is still a bounty going. Here is my GridView code:
GridView gridView= new GridView(this);
gridView.setLayoutParams(new GridView.LayoutParams(customValue,LayoutParams.FILL_PARENT, Gravity.CENTER_HORIZONTAL));
gridView.setNumColumns(someInt);
gridView.setAdapter (new MyCustomAdapter(this));
One way to ensure the padding appears same on screens with different density is by converting it to DIP units.
int padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, -5, getResources().getDisplayMetrics());
Other thing you can try is to define a null drawable in xml..
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="null_drawable">@null</drawable> ... </resources>
Then call
setSelector(R.drawable.null_drawable);
Update:
Define your
GridView
in its own xml and inflate it.layout/mygrid.xml
<?xml version="1.0" encoding="utf-8"?> <GridView android:layout_width="fill_parent" android:layout_height="fill_parent" android:listSelector="@null"/>
In java,
GridView gridView = (GridView)inflater.inflate(R.layout.mygrid, null); gridView.setLayoutParams(new GridView.LayoutParams(customValue, LayoutParams.FILL_PARENT)); gridView.setNumColumns(someInt); gridView.setAdapter (new MyCustomAdapter(this));
这篇关于周围的GridView删除多余的空间编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!