Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - combine multiple images into one ImageView

I'm looking for help developing (or a library) which can allow me to merge together multiple images into one imageview.

My application is grouping together interactions between users, instead of displaying them singularly, and therefore I would like to merge all of their avatars, so that one adapter cell visualizes a "group".

A fantastic example of this is done on facebook.com's chat as such:

Image showing combined avatars

My question is, how can I provide this functionality in Android / Java? Presumably, it could a number of images between 1 and 4. Please let me know of any advice you can give :)

like image 610
Jonty800 Avatar asked Jul 14 '15 11:07

Jonty800


People also ask

Can you set an image to multiple Imageview can you display the same Imageview multiple times?

Can you set an image to multiple Imageview can you display the same Imageview multiple times? Multiple Views of an Image You can also set multiple views for an image in the same scene. The following program is an example that demonstrates how to set various views for an image in a scene in JavaFX.

How do I combine photos?

Download Image Combiner from Google Play on your Android mobile device. Tap the Add Picture button at the bottom of the screen. Select the photos you want to combine. When you've chosen the photos you want to use, hit Combine Images at the bottom of the screen.


1 Answers

You can use MultiImageView.

Add dependency in app.gradle:

compile 'com.github.stfalcon:multiimageview:0.1'

Add MultiImageView to layout xml file

<com.stfalcon.multiimageview.MultiImageView
    android:id="@+id/iv"
    android:layout_width="100dp"
    android:layout_height="100dp"/>

In java class find view by id:

final MultiImageView multiImageView = (MultiImageView) findViewById(R.id.iv);

For adding image to MultiImageView use method addImage(Bitmap bitmap). For exapple:

multiImageView.addImage(BitmapFactory.decodeResource(getResources(), R.drawable.avatar1));

For setting shape of MultiImageView use method setShape(MultiImageView.Shape shape).

multiImageView.setShape(MultiImageView.Shape.RECTANGLE);//Rectangle with round corners
multiImageView.setShape(MultiImageView.Shape.CIRCLE);//Circle
multiImageView.setShape(MultiImageView.Shape.NONE);//Without shape

enter image description here
Check github link for more information:

I think it is what you needed

like image 52
Anton Bevza Avatar answered Nov 10 '22 12:11

Anton Bevza