在不改变 ImageButton 形状的情况下使用 setImageBitmap

Using setImageBitmap without changing the shape of ImageButton

我的相机应用程序有一个圆形的 ImageButton 来显示用户拍摄的最后一张图像,就像许多其他相机应用程序一样。为了给 ImageButton 一个圆形,我使用了一种使用可绘制对象作为背景的样式,并且我使用 ImageButton 的 setImageBitmap 函数来显示图像缩略图。但问题是在设置位图后ImageButton 的形状变为正方形。如何在不更改 ImageButton 形状的情况下执行此操作?

您可以使用 circular Image view 库来实现

<CircularImage.CircleImageView
                android:id="@+id/profilecircularimage"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerVertical="true"
                android:layout_gravity="center_vertical|center_horizontal"
                android:layout_marginTop="10dp"
                android:clickable="true"
                android:src="@drawable/cameraImage"
                app:civ_border_color="@color/primary"
                app:civ_border_width="2dp" />