Android开发圆形头像

作者: GB_speak | 来源:发表于2017-06-15 15:42 被阅读305次

目前在应用开发中,矩形的头像基本没有了,大多是圆形或圆角矩形,本文简简单单轻轻松松帮你搞定圆形或圆角矩形的头像。

可以自定义控件实现,而本文使用的是第三方开源控件RoundedImageView,改控件支持圆形、椭圆、圆角矩形等,使用非常方便。
添加RoundedImageView依赖
使用RoundedImageView有两种操作方法,实质都是添加库依赖。
方法一: 在Android Studio中,可进入模块设置中添加库依赖。 进入Module结构设置添加库依赖(如下图)

Paste_Image.png 输入RoundedImageView然后搜索添加。
Paste_Image.png
方法二: 在Moudle的build.gradle中添加如下代码,添加完之后在Build中进行下Make Module操作(编译下Module),使自己添加的依赖生效。
repositories {
    mavenCentral()
}

dependencies {
    compile 'com.makeramen:roundedimageview:2.2.1'
}```
Layout中使用

添加了库依赖之后,我们就可以使用该控件了。

先看看效果: 
![Paste_Image.png](http:https://img.haomeiwen.com/i5423625/78097e0d0a20d26a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这里我设置的是圆形:

<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/zr"
app:riv_oval="true" />```

控件属性:
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"
          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"
          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"
          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"
          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: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" />
Paste_Image.png Paste_Image.png

相关文章

  • Android开发圆形头像

    目前在应用开发中,矩形的头像基本没有了,大多是圆形或圆角矩形,本文简简单单轻轻松松帮你搞定圆形或圆角矩形的头像。 ...

  • Android开发——圆形头像

    两种方法,自己写代码实现,用第三方开源库 一、第三方开源控件RoundedImageViewRoundedImag...

  • Android实现头像上传

    Android实现本地上传图片并设置为圆形头像 Android实现类似换QQ头像功能(图片裁剪) android上...

  • Android圆形头像

    现在基本上很多APP会用到圆形头像,而关于这方面也有很多的示例。今天我也把我的分享一下给大家,也是新手一枚,不好的...

  • android ------ 登录圆形头像之网络加载与缓存到本地

    Android开发中常常有用户头像显示,似乎大多数都是圆形显示,如果每次加载网络头像,会频繁的请求网络,所以本文主...

  • Android 加载圆形头像

    在 Android 中,加载网络图片还是本地图片,三方库Glide必不可少 1、导入依赖 implementati...

  • android圆形头像实现

    今天我们学习圆形头像的实现原理,先上图 基本上能满足一般的圆形头像功能实现其中包括控件的大小,控件四个角的弧度控制...

  • Xamarin.iOS 圆形图片裁剪

    本文主要讲解在实际开发过程中圆形图片的实现过程 在项目开发中我们经常会使用圆形头像图片,例如登陆页面的头像,个人页...

  • iOS开发——制作圆形头像

    在iOS7之后,我们能发现许多应用都开始使用圆形来作为用户头像的形状,代表App就是腾讯QQ了,QQ的头像就是圆形...

  • Android实现圆形头像效果

    效果截图 实现原理 对于圆形头像的实现,其实就是对方形图像做某些处理,以达到圆形头像的效果。一般我们会通过Canv...

网友评论

    本文标题:Android开发圆形头像

    本文链接:https://www.haomeiwen.com/subject/jrquqxtx.html