AvatarImageView
![Android Arsenal][1]
#??? ???????????????????????????????????????????????????????????????????????????????????????????????????????1????clip?????????????clip??
##???
![1.0.2??clip????][2] ![?????????][3] ![????][5]##?????
compile 'cn.carbs.android:AvatarImageView:1.0.4'
##?????
- ???????
- ???????
- ?????????????????
- ?????????
- ????????????????????????????????????????????????????????????????????????????
- ??????ImageView???onDraw()????super.onDraw()???????drawable????????????view?????Glide??????????????????????????????;
- ??padding?
- ????????clip??
- ?????clip???????maskratio??????????
##????? ###1.0.4
- ??rx? ###1.0.3
- ?????????SquareAvatarImageView?????????? ###1.0.2
- ???????clip??
##????? ?????wrap_content??
##????????? ??shader + matrix????????????????shader??????????????matrix????
##????? (1)????????????
AvatarImageView aiv = (AvatarImageView) this.findViewById(R.id.aiv);
//????? aiv.setImageResource(R.drawable.id_014);
//??? aiv.setDrawable(drawable);
//??? aiv.setBitmap(bitmap);
//??? aiv.setImageDrawable(drawable);
//????? aiv.setTextAndColor("?", AvatarImageView.COLORS[0]);
//????????????????????????clip?????????clip?? //??? aiv.setTextAndColorSeed("?","??");
//“??”??????backgroundcolor?seed
(2)?Glide????
Glide
.with(activity)
.load(picurl)
.centerCrop()
.crossFade()
.into(aiv);
##????? 1.????
compile 'cn.carbs.android:AvatarImageView:1.0.3'
2.layout??????view
<cn.carbs.android.avatarimageview.library.AvatarImageView
android:id="@+id/item_avatar"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp"
app:aiv_BoarderWidth="2dp"//????
app:aiv_ShowBoarder="false"//??????
app:aiv_TextSizeRatio="0.4"/>//??????????????
##?? ####[CircleImageView][4]
#English
##Abstract AvatarImageView on Android platform can display circle text or circle image
##Screenshot
![load local image resources][2] ![load local image resources][3]##Main features:
- show circle image(including bitmap and drawable);
- show circle text(can generate a colorful background for text);
- the textsize can be modified according to the ratio of AvatarImageView's width;
- can add a circle boarder for text or image, and the boarder can be adjusted in stroke width or color;
- the image or text is aways in the center; the rule is : if the image's width is larger than height, then get the center square of the image, with the same length side of image's width. vice versa.
- since AvatarImageView extends from ImageView, and remove super.onDraw(), and override setImageResoure() setImageDrawable(), then we can use Glide or other famouse Loading Image Libary to load image into AvatarImageView conveniently.
- surpport padding;
- have clip effect if the text's length > 1
- can set the clip effect's amplify ratio by setting mask ratio
##Attention not support wrap_content pattern temporarily
##How to use it: (1)How to set image or text
AvatarImageView aiv = (AvatarImageView) this.findViewById(R.id.aiv);
//set image? aiv.setImageResource(R.drawable.id_014);
//or? aiv.setDrawable(drawable);
//or? aiv.setBitmap(bitmap);
//or? aiv.setImageDrawable(drawable);
//set text: aiv.setTextAndColor("Android", AvatarImageView.COLORS[0]);
//set backgroundcolor directly, if the text's length > 1, will have clip effect //or aiv.setTextAndColorSeed("Android","Android platform");
//"Android platform" as the backgroundcolor seed
(2)use with Glide:
Glide
.with(activity)
.load(picurl)
.centerCrop()
.crossFade()
.into(aiv);
##add to your project 1.add dependence
compile 'cn.carbs.android:AvatarImageView:1.0.4'
2.add into xml layout file
<cn.carbs.android.avatarimageview.library.AvatarImageView
android:id="@+id/item_avatar"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp"
app:aiv_BoarderWidth="2dp"//
app:aiv_ShowBoarder="false"//
app:aiv_TextSizeRatio="0.4"/>//equals textsize divides circle diameter
##Thanks ####[CircleImageView][4]
License
Copyright 2016 Carbs.Wang (AvatarImageView) Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
[1]: https://img.shields.io/badge/Android%20Arsenal-AvatarImageView-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3820 [2]: https://github.com/Carbs0126/Screenshot/blob/master/avatar_image_view_3_in_1.jpg [3]: https://github.com/Carbs0126/Screenshot/blob/master/avatar_image_view_2_in_1.jpg [4]: https://github.com/hdodenhof/CircleImageView [5]: https://github.com/Carbs0126/Screenshot/blob/master/SquareAvatarImageView.png