我有一个带有默认可绘制图像的 ImageButton。从代码中我设置了 ImageButton 布局大小,因此在此修改后,由于 centerInside scaleType,图像不会覆盖整个按钮。在 OnClick 事件中,我使用此代码替换 ImageButton 的图像。
button.setImageBitmap(img);
button.invalidate();
新图像比旧图像小。更换后新图像出现,但旧图像部分可以在新图像周围看到。如何强制清除旧图像或简单地重绘整个 ImageButton 以仅显示新图像?
<ImageButton
android:id="@+id/btnPhotoFront"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:contentDescription="@string/front"
android:scaleType="centerInside"
android:src="@drawable/camera" />
我尝试使用 android:background="#00000000" 但没有效果。仅当我不设置背景并保留默认的灰色按钮层时,重绘才有效。