我的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);
如何删除此额外的灰阶空白?
设置图像按钮背景为空。例如。
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”是放大为片段或活动的布局。