Android:“图像”按钮的页边空白

问题描述 投票:0回答:2

我的Android项目中有一些图片按钮。但它们有一些像这样的图片空白边缘(我从真实设备上获取了这张图片):

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS96bmd5WS5qcGcifQ==” alt =“在此处输入图像描述”>

如何删除它们?我使用了此代码,但没有任何效果。

 ib.setAdjustViewBounds(true);     

图像按钮只是在Java中定义的,我在xml中没有。

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

如何删除此额外的灰阶空白?

android android-layout android-imagebutton
2个回答
3
投票

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

ib.setBackground(null);

0
投票

默认情况下,其背景具有边距。

使用代码:

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”是放大为片段或活动的布局。

© www.soinside.com 2019 - 2024. All rights reserved.