デフォルトの描画可能な画像を持つ 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" で試しましたが、効果がありません。再描画は、背景を設定せず、デフォルトの灰色のボタン レイヤーのままにした場合にのみ機能します。