Android轻松实现图片的圆形化处理(基于xml文件快速实现)

短命女 2024-04-01 08:54 80阅读 0赞

会持续发布关于Android系列文章以及小技巧,好用的第三方库等等

目录

前言

一、引入第三方依赖库

二、使用方法

总结


前言

大家知道,在Android应用开发中,对于图形的处理是非常重要的,它在一定程度上决定着UI界面的美观,今天为大家介绍一个比较好用的图片圆形化处理的第三方库,轻松实现图片圆形化处理,接下来让我们一起学习吧。


一、引入第三方依赖库

此处引入的是github中的比较好用的第三方的开源库,相关地址如下:

628802d667794b7cac37cf80e88466f3.png

依赖如下:

  1. implementation 'de.hdodenhof:circleimageview:3.1.0'

导入app模块下的build.gradle中即可正常使用。

大致效果如下:

120efc836efa46ce8f57106911b3d6aa.png


二、使用方法

我们需要知道的是,使用这个开源库,是不需要在Activity中进行相关处理的,只需要在xml布局文件中使用开源库即可实现效果,方便快捷。

布局文件如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:orientation="vertical"
  8. tools:context=".MainActivity">
  9. <TextView
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:gravity="center"
  13. android:textColor="@color/black"
  14. android:textSize="20sp"
  15. android:text="图片圆形化处理"/>
  16. <ImageView
  17. android:layout_width="300dp"
  18. android:layout_height="300dp"
  19. android:src="@drawable/file"
  20. android:layout_gravity="center"/>
  21. <de.hdodenhof.circleimageview.CircleImageView
  22. android:layout_marginTop="50dp"
  23. android:layout_width="300dp"
  24. android:layout_height="300dp"
  25. android:layout_gravity="center"
  26. android:src="@drawable/file"
  27. />
  28. </LinearLayout>

我在这里特意加了一个对比,未处理的图片和处理过的图片的前后变化,效果如下:

120efc836efa46ce8f57106911b3d6aa.png

总结

有任何问题请在评论区交流,或者直接私信我,看到就会回复的。

发表评论

表情:
评论列表 (有 0 条评论,80人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Android圆形头像实现

    ![这里写图片描述][SouthEast] 如图所示,实现一个QQ圆形头像,话不多说,直接上代码,继承ImageView类,重写里面的方法: package com