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

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

目录

前言

一、引入第三方依赖库

二、使用方法

总结


前言

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


一、引入第三方依赖库

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

 依赖如下:

implementation 'de.hdodenhof:circleimageview:3.1.0'

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

 大致效果如下:


二、使用方法

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

布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="@color/black"
        android:textSize="20sp"
        android:text="图片圆形化处理"/>

    <ImageView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:src="@drawable/file"
        android:layout_gravity="center"/>


    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_marginTop="50dp"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:src="@drawable/file"
        />

</LinearLayout>

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

 

总结

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

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ken'

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值