AvatarImageView is android ImageView library for displaying images in multiple styles.
The main goal for developing this library was to make it easy for all programmers to load image in various styles. Our library is:
- Easy to implement: Just add jCenter dependency for project in your app level gradle file and voila! Half of your work is done. The other half is to implement it in your project. We'll talk about that below :)
- Easy to understand: Simple and neat code with proper documentation.
Add the dependency in project level gradle file.
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Add the dependency from jCenter to your app's (not project) build.gradle
file.
dependencies {
implementation 'com.github.indra58:AvatarImageview:Tag'
}
- Android API 14+ is required as the
minSdkVersion
in your build.gradle. - Add permissions in your
AndroidManifest.xml
to load image.
<!-- if you want to load images from the internet -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- if you want to load images from a file OR from the internet -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
In your activity or fragment, insert AvatarImageView
custom view.
AvatarImageView
extends FrameLayout
, so all of its standard attributes are available to you.
<imageview.avatar.com.avatarimageview.AvatarImageView
android:id="@+id/imageView"
android:layout_width="72dp"
android:layout_height="72dp" />
1. app:aiv_radius="12" (integer)
2. app:aiv_margin="5" (integer)
3. app:aiv_shape="normal" or "round" or "curved" (String)
4. app:aiv_text_size="18" (float)
5. app:aiv_font_family="@font/your_font_name" (reference)
- Round Image
<imageview.avatar.com.avatarimageview.AvatarImageView
android:id="@+id/imageView"
android:layout_width="72dp"
android:layout_height="72dp"
app:aiv_shape="round" />
Then, in your activity:
AvatarImageView avatarImageView = findViewById(R.id.imageView);
UserAvatar userAvatar = new UserAvatar("https://yourimageurl or file absolute path or file itself", "Avatar Name");
avatarImageView.setAvatar(userAvatar);
- Add radius to your image
<imageview.avatar.com.avatarimageview.AvatarImageView
android:id="@+id/imageView"
android:layout_width="72dp"
android:layout_height="72dp"
app:aiv_radius="20"
app:aiv_shape="curved" />
Then, in your activity:
AvatarImageView avatarImageView = findViewById(R.id.imageView);
avatarImageView.setAvatar("https://yourimageurl or file absolute path", "Avatar Name");
Note: If you want normal image with no roundness or curve in edges. Don't use app
provided properties
- If you want to show text(nickname) instead of image like in the preview shown below:
Do this:
AvatarImageView avatarImageView = findViewById(R.id.imageView);
avatarImageView.setAvatar("", "Your Avatar Name");
Additional properties supported:
<imageview.avatar.com.avatarimageview.AvatarImageView
android:id="@+id/imageView"
android:layout_width="72dp"
android:layout_height="72dp"
app:aiv_text_size="26"
app:aiv_font_family="@font/your_font_name" />
DemoApp Coming Soon!!!