前言
在Android中有时候需要用到圆角布局,或者圆角头像,实现办法有很多,但是各种办法有坑没坑那就是另一说了,今天就说三种办法,CardView、Shape、自定义View。
CardView
首先说第一种CardView,这是官方提供的一个控件,使用他需要引入,具体什么时候发布的就不知道了。
使用CardView非常简单,只需要给他配置app:cardCornerRadius圆角大小就行。implementation 'androidx.cardview:cardview:1.0.0'<?xml version="1.0" encoding="utf-8"?>
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">
android:layout_width="100dp"
android:layout_height="100dp"
app:cardCornerRadius="50dp"
app:cardElevation="0dp"
app:cardUseCompatPadding="false">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/test">