今天使用GridView, 发现点中某一Item时选中部分的背景都变成高亮, 范围超过图标大小, 显示效果很不好。 想到要改成选中时高亮部分只有图标大小那部分, 这就需要设置item的间距。 一开始使用了setColumnWidth,发现无法达到效果, 设置StretchMode也不行。 上网找了一遍也没什么有效的结论。 后来自己想了想, setVerticalSpacing和setHorizontalSpacing是有效果的, 但是距离屏幕边还是0. 只要再把gridview本身设置一个padding就可以了。 所做修改如下:
<GridView
android:id="@+id/main_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:numColumns="auto_fit"
android:horizontalSpacing="40dp"
android:verticalSpacing="40dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
/>
这样达到了我所需要的效果。
Grid调整间距
猜你喜欢
转载自seya.iteye.com/blog/1688330
今日推荐
周排行