Loading

RoundedImageView,实现圆形、圆角矩形的注意事项

RoundedImageView是gitHub上面的一个开源组件(https://github.com/vinc3m1/RoundedImageView),实现一些圆形或者圆角矩形是很方便的,

 1 <com.makeramen.roundedimageview.RoundedImageView
 2                 android:id="@+id/iv_hint"
 3                 android:layout_width="@dimen/x36"
 4                 android:layout_height="@dimen/x36"
 5                 android:src="@drawable/icon_no_photo_round"
 6                 android:scaleType="centerCrop"
 7                 app:riv_corner_radius="@dimen/x18"
 8                 app:riv_border_color="@color/white50"
 9                 app:riv_border_width="@dimen/x1"
10                 app:riv_tile_mode="clamp"
11                 app:riv_oval="true"
12                 app:riv_mutate_background="true"
13                 />

 

其中,riv_corner_radius是指圆角的大小,简单来说,等于宽度一半时,就是圆形了;小于宽度的一半就是圆角矩形了。

这里特别要注意的几点:

1、riv_tile_mode 有三种clamp,repeat,mirror,分别是指缩放、重复、镜像,实现后两种的效果,最后是src的分辨率小于RoundedImageView的分辨率才比较直观显示(如这里121x121---》70x70):

2、src原图与RoundedImageView的比例关系,使用时要注意设置android:scaleType="",一般来说,有fitCenter,centerCrop,CenterInside,fitXY等几种(具体区别可以看http://www.cnblogs.com/chq3272991/p/5710498.html)

    如要获得一个圆形,如果src的长宽比为4:3,如果设置fitCenter,把原图按比例扩大或缩小到ImageView的高度,居中显示,那么效果如下:

原图:

显然是得不到一个圆形的,那么试试改成fitXY、center、centerCrop:

这过程也就是说,要先通过scaleType来调整(裁剪)原图,然后再进行切圆角、加边框处理,这里用centerCrop才符合要求。类似的还有很多,大家遇到可以提出来共同探讨下。

posted @ 2016-08-01 15:57  集君  阅读(4323)  评论(0编辑  收藏  举报