Android 安卓:图像按钮有多余的边距

Android 安卓:图像按钮有多余的边距,android,android-layout,android-imagebutton,Android,Android Layout,Android Imagebutton,我的android项目中有一些图像按钮。但是它们有一些灰色的边缘,比如这张照片(我从真实设备上取下这张照片): 我如何才能删除它们?? 我使用了这个代码,但没有任何效果 ib.setAdjustViewBounds(true); 图像按钮只是在java中定义的,我在xml中没有 ib = new ImageButton(this); ib.setImageResource(R.drawable.image); ib.setAdjustViewBounds(true); i

我的android项目中有一些图像按钮。但是它们有一些灰色的边缘,比如这张照片(我从真实设备上取下这张照片):

我如何才能删除它们?? 我使用了这个代码,但没有任何效果

 ib.setAdjustViewBounds(true);     
图像按钮只是在java中定义的,我在xml中没有

 ib = new ImageButton(this);
 ib.setImageResource(R.drawable.image);
 ib.setAdjustViewBounds(true);
 ib.setLayoutParams(ibrllp);

如何删除此附加灰色边距?

将图像按钮背景设置为空。例如

ib.setBackground(null);

设置图像按钮背景为空。例如

ib.setBackground(null);

默认情况下,它有一个带边距的背景

代码:

ImageButton imageButton = ImageButton.class.cast(rootView.findViewById(R.id.imageButton));
imageButton.setBackground(null);
在xml文件中:

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:background="@null" />


“rootView”是膨胀为片段或活动的布局。

默认情况下,它有一个带边距的背景

代码:

ImageButton imageButton = ImageButton.class.cast(rootView.findViewById(R.id.imageButton));
imageButton.setBackground(null);
在xml文件中:

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:background="@null" />


“rootView”是膨胀为片段或活动的布局。

在哪里可以看到它们?我是说。。。灰色边缘?!为按钮使用on样式,并将边距设置为0。将图像按钮背景设置为空。ib.背景(空)@DerGolem在我的图像按钮附近谢谢大家。。。。ib.背景(空);是为我工作的…你在哪里看到他们?我是说。。。灰色边缘?!为按钮使用on样式,并将边距设置为0。将图像按钮背景设置为空。ib.背景(空)@DerGolem在我的图像按钮附近谢谢大家。。。。ib.背景(空);是为我工作的。。。