我的Android应用程序中有一个GridView,其中包含许多ImageView.屏幕上的空间有限,我希望图像尽可能多地占用可用空间.不幸的是,GridView总是在ImageViews的外边缘留下5个像素的空屏幕空间(ImageViews之间的空间设置为水平/垂直间距并且行为正确).空白空间有点像ImageViews的边缘,但我无法摆脱它.有谁知道是什么导致了这个"边界"以及我如何摆脱它(或者至少让它变小)?谢谢.
更新:我通过在Adapter类的getView()方法中膨胀.xml文件来创建ImageViews.这是我正在膨胀的xml:
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#FF00FF" />
Run Code Online (Sandbox Code Playgroud)
我在我的布局xml文件中定义了GridView,如下所示:
<GridView
android:id="@+id/mygrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/abutton"
android:layout_marginBottom="8dp"
android:numColumns="5" android:background="#FF0000"/>
Run Code Online (Sandbox Code Playgroud)
这是问题的屏幕截图.我的GridView中的红色区域.紫色区域是我的ImageViews.显示的图像是一个简单的蓝色矩形,中心是透明的.图像是45x45像素(但我的应用程序只有30x30像素 - 稍后我会担心).紫色周围的红色边框是我想要消除的.

我尝试删除GridView周围的红色边框,以完全填充我的日历屏幕(没有从左,右和顶部填充).
margin=0
padding=0
background=@null
Run Code Online (Sandbox Code Playgroud)
不解决问题.我不使用任何9path背景图像.有什么问题 ?

我想删除网格视图中出现的额外填充.我有大小128*128的图像,它将占用网格中的单元格.但不知何故,有一个额外的空间被添加到网格的内容.
经过一些研究,我能够确定我必须覆盖网格视图的listSelector属性.现在这是我的问题 - 我知道我必须在这里指定像xml drawable这样的东西,但是要指定什么?我尝试使用带有填充和笔划设置为0dp的形状可绘制无效.
有人可以帮我弄这个吗.谢谢!
编辑:好的 - 这是我的UI的副本.并且XML布局如下:
<GridView android:id="@+id/GV_A2ZMenu" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:numColumns="4"
android:layout_gravity="top" android:stretchMode="columnWidth"
android:gravity="center" android:listSelector="@null" />
Run Code Online (Sandbox Code Playgroud)
我正在使用BaseAdapter类来填充gridView.这是它的代码:
public class AtoZMenu extends BaseAdapter {
private static Context AppC;
private Integer[] MenuImg = { R.drawable.alphabet_a, R.drawable.alphabet_b,
R.drawable.alphabet_c, R.drawable.alphabet_d,
R.drawable.alphabet_e, R.drawable.alphabet_f,
R.drawable.alphabet_g, R.drawable.alphabet_h,
R.drawable.alphabet_i, R.drawable.alphabet_j,
R.drawable.alphabet_k, R.drawable.alphabet_l,
R.drawable.alphabet_m, R.drawable.alphabet_n,
R.drawable.alphabet_o, R.drawable.alphabet_p,
R.drawable.alphabet_q, R.drawable.alphabet_r,
R.drawable.alphabet_s, R.drawable.alphabet_t,
R.drawable.alphabet_u, R.drawable.alphabet_v,
R.drawable.alphabet_w, R.drawable.alphabet_x,
R.drawable.alphabet_y, R.drawable.alphabet_z };
public AtoZMenu(Context C) {
AppC = C;
}
public int getCount() {
return …Run Code Online (Sandbox Code Playgroud) 我有以下Gridview代码(制作日历).
<GridView
android:id="@+id/calendar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/rl1"
android:layout_below="@+id/ll2"
android:columnWidth="250dp"
android:numColumns="7" >
</GridView>
Run Code Online (Sandbox Code Playgroud)
Grid_Cell如下.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/calendar_button_selector" >
<Button
android:id="@+id/calendar_day_gridcell"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/calendar_button_selector"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000"
android:textSize="14.47sp" >
</Button>
<TextView
android:id="@+id/num_events_per_day"
style="@style/calendar_event_style"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
</TextView>
Run Code Online (Sandbox Code Playgroud)
我想在行和列之间不设置空格.
现有视图如下.

请帮帮我...先谢谢.