除了Anton Bevza的回答之外,我还想补充一些内容。
他们的库存在一些缺点,在分支中已经得到了修复。
在app.gradle中添加依赖项:
implementation 'com.github.martipello:MultiImageView:1.0.8.2'
将MultiImageView添加到布局XML文件中。
<com.sealstudios.multiimageview.MultiImageView
android:id="@+id/iv"
android:layout_width="100dp"
android:layout_height="100dp"
app:shape="circle" />
要设置MultiImageView的形状,请在布局xml文件中使用属性
app:shape="circle" //Circle
app:shape="rectangle" //Rectangle with round corners
app:shape="none" //Without shape
同时你也可以通过方法改变形状:
multiImageView.setShape(MultiImageView.Shape.RECTANGLE);
multiImageView.setShape(MultiImageView.Shape.CIRCLE);
multiImageView.setShape(MultiImageView.Shape.NONE);
在Java类中通过ID查找视图:
final MultiImageView multiImageView = findViewById(R.id.iv);
要向MultiImageView添加图像,请使用addImage(Bitmap bitmap)方法。例如:
multiImageView.addImage(BitmapFactory.decodeResource(getResources(), R.drawable.avatar));
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), ImageUri);
multiImageView.addImage(bitmap);