android圆形图片开源框架roundedimageview的使用

在Android开发,图片是很常用的,用户头像基本上都是圆形的,我们可以自己写画布类,将其变为圆形的,但是比较麻烦获取bitmap体验也不好,在这里使用开源框架roundedimageview。

或者CircleImageView框架

先看看效果: 

1.首先在build.gradle中添加:

compile 'com.makeramen:roundedimageview:2.3.0'

2.在布局中:

   <com.makeramen.roundedimageview.RoundedImageView
        android:id="@+id/ImageView01"
        android:scaleType="centerCrop"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:src="@mipmap/tx"
        app:riv_oval="true"
        app:riv_corner_radius="100dp"
       />

必须添加属性:

增加属性,android:scaleType="centerCrop"

不然得到的事椭圆形;(附图)

扫描二维码关注公众号,回复: 11146114 查看本文章

实现效果变成椭圆形、

这过程也就是说,要先通过scaleType来调整(裁剪)原图,然后再进行切圆角、加边框处理,这里用centerCrop才符合要求

3.其余使用与imageview类似。

4.控件属性: 
riv_border_width: 边框宽度 
riv_border_color: 边框颜色 
riv_oval: 是否圆形 
riv_corner_radius: 圆角弧度 
riv_corner_radius_top_left:左上角弧度 
riv_corner_radius_top_right: 右上角弧度 
riv_corner_radius_bottom_left:左下角弧度 
riv_corner_radius_bottom_right:右下角弧度

    <com.makeramen.roundedimageview.RoundedImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@mipmap/avatar"
          app:riv_border_color="#333333"
          app:riv_border_width="2dp"
          android:scaleType="centerCrop"
          app:riv_oval="true" />
 
    <com.makeramen.roundedimageview.RoundedImageView
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:scaleType="fitCenter"
          android:src="@mipmap/avatar"
          app:riv_border_color="#333333"
          app:riv_border_width="2dp"
          app:riv_corner_radius="10dp"
          app:riv_mutate_background="true"
          app:riv_oval="false"
          android:scaleType="centerCrop"
          app:riv_tile_mode="repeat" />
 
    <com.makeramen.roundedimageview.RoundedImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:scaleType="fitCenter"
          android:src="@mipmap/avatar"
          app:riv_border_color="#333333"
          app:riv_border_width="2dp"
          android:scaleType="centerCrop"
          app:riv_corner_radius_top_left="25dp"
          app:riv_corner_radius_bottom_right="25dp"
          app:riv_mutate_background="true"
          app:riv_oval="false"
          app:riv_tile_mode="repeat" />
 
   <com.makeramen.roundedimageview.RoundedImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:scaleType="fitCenter"
          android:src="@mipmap/avatar"
          app:riv_border_color="#333333"
          android:scaleType="centerCrop"
          app:riv_border_width="2dp"
          app:riv_corner_radius_top_right="25dp"
          app:riv_corner_radius_bottom_left="25dp"
          app:riv_mutate_background="true"
          app:riv_oval="false"
          app:riv_tile_mode="repeat" />
 
   <com.makeramen.roundedimageview.RoundedImageView
          android:layout_width="96dp"
          android:layout_height="72dp"
          android:scaleType="center"
          android:scaleType="centerCrop"
          android:src="@mipmap/avatar"
          app:riv_border_color="#333333"
          app:riv_border_width="2dp"
          app:riv_corner_radius="25dp"
          app:riv_mutate_background="true"
          app:riv_oval="true"
          app:riv_tile_mode="repeat" />
原创文章 63 获赞 33 访问量 10万+

猜你喜欢

转载自blog.csdn.net/hdhhd/article/details/100073735