如何删除图像按钮周围的白色填充?

How do I remove the white padding around my imagebutton?

我的应用程序如下所示:

我希望我的两个图像按钮完全填充我的线性布局的 space,就像复选框所做的那样 - none 它们周围的白色填充。我尝试了很多关于 Whosebug 的建议 = 将背景设置为“@null”等等,但是 none 成功了。

我想我可以试试 ImageView,但我想要那种 'click' 效果。

有什么想法吗?这是我的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/ListView_2"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_weight="1">
    </ListView>


    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/editText"
        android:gravity="center"
        android:inputType="phone"
        android:background="#d9d9d9">
    </EditText>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="horizontal" >

    <CheckBox
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:background="#ffa500"
        android:text="New CheckBox"
        android:id="@+id/checkBox"
        android:layout_weight="2"
        >
    </CheckBox>

        <ImageButton
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:id="@+id/imageButton"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

        <ImageButton
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:id="@+id/imageButton2"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

    </LinearLayout>

</LinearLayout>

您可以使用 setPadding() 删除图像和边框之间的 space。这实际上对我在学校做类似的东西有用。

Check out this answer.

请将您的 ImageView 背景设置为透明,并在 src 中设置您的颜色或绘图。像这样:

<ImageButton
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:id="@+id/imageButton"
        android:background="@android:color/transparent"
        android:src="?colorPrimary"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" />