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>

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

 

总结

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

猜你喜欢

转载自blog.csdn.net/m0_58941767/article/details/127426623