Android 如何拉伸按钮以适应GridView

Android 如何拉伸按钮以适应GridView,android,xml,view,Android,Xml,View,我有三个GrindView的活动。我用自定义SimpleCorsorAdapter填充这些视图。每个单元格中都有一个按钮,我需要将其拉伸到GrindView的单元格中。我还需要在格林德维之间没有空闲的空间。我已经尝试设置填充/边距,但没有效果。以下是XML: 主视图: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:

我有三个GrindView的活动。我用自定义SimpleCorsorAdapter填充这些视图。每个单元格中都有一个按钮,我需要将其拉伸到GrindView的单元格中。我还需要在格林德维之间没有空闲的空间。我已经尝试设置填充/边距,但没有效果。以下是XML:

主视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<GridView android:id="@+id/gridview1" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:numColumns="5"
    android:gravity="center" />

<GridView android:id="@+id/gridview2" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:numColumns="5"
    android:gravity="center" />

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridview3" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:numColumns="4"
    android:gravity="center" />
单元格:

截图:


谢谢你的帮助

我认为您必须为按钮设置自己的可绘制图像,而不是使用标准系统图像。除非我弄错了,按钮的标准MDPI图像有一个内置的透明边框,水平面上有3个像素,顶部有1个像素,底部有4个像素。因此,即使这个按钮图像被完全扩展到100%填充网格单元,它仍然会包含这个透明的边框,因此看起来不会完全填充网格单元。这是基于默认按钮图像为btn_default_normal.9.png的假设

不要使用按钮,而是看一看,它允许您设置自己的图像。或者,要使用常规按钮,您可能需要使用可绘制的状态列表设置按钮的背景图像。更多信息,请查看按钮样式部分

-


但是,我现在在文档中看到,显式设置填充值将覆盖在后台找到的相应填充。我看到你提到你试过设置填充物,但是你试过将填充物设置为零吗?

Darn,我希望了解一些性感的新GrindView!我不知道我是否明白你想做什么。这个解决方案是否可能只是从你手机的线性布局和按钮中删除android:padding=1dip?也许这个屏幕截图会更好。我只想把按钮拉伸到整个橙色区域。因此,它们周围几乎没有黑色背景。如果我把填充物从按钮单元中移除,就会发生这种情况——你说得对。为按钮设置我自己的背景图像很有帮助,现在整个区域都被覆盖了。谢谢你的回答!仅供参考-将填充设置为零没有帮助。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:padding="1dip"
android:layout_height="fill_parent" android:orientation="horizontal">

<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:padding="1dip"
    android:layout_height="fill_parent" android:id="@+id/textButton" />